fork(1) download
  1. #include <iostream>
  2. #include <typeinfo>
  3. using namespace std;
  4.  
  5. class X {
  6. public:
  7. template<typename T> bool InstanceOf() {
  8. cout << typeid(*this).name() << " " << typeid(T).name() << endl;
  9. return typeid(T) == typeid(*this);
  10. }
  11. };
  12.  
  13. class A: public X {};
  14.  
  15. int main() {
  16. A a;
  17. cout << a.InstanceOf<X>();
  18. return 0;
  19. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1X 1X
1