1
0

19_rtti.cpp 529 B

123456789101112131415161718192021222324252627282930
  1. #include <iostream>
  2. #include <typeinfo>
  3. using namespace std;
  4. class Base
  5. {
  6. virtual void dummy()
  7. {
  8. // Required to make class polymorphic
  9. }
  10. // Some base class
  11. };
  12. class Derived : public Base
  13. {
  14. // Some derived class
  15. };
  16. int main()
  17. {
  18. Base *base = new Base;
  19. Base *derived = new Derived;
  20. // These outputs are implementation-dependent and may need to be demangled
  21. cout << "Type of base variable is " << typeid(*base).name() << endl;
  22. cout << "Type of derived variable is " << typeid(*derived).name() << endl;
  23. return 0;
  24. }