fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3. using namespace std;
  4.  
  5. class base
  6. {
  7. public:
  8. template<typename T>
  9. void BindType( ) // do something with the type
  10. { cout << typeid(T*).name()<<endl; }
  11. virtual ~base() {};
  12. };
  13.  
  14. class derived : public base
  15. {
  16. public:
  17. void foo() { BindType<decltype(this)>( ); }
  18. };
  19.  
  20. class derived_once_more : public derived
  21. {
  22. };
  23.  
  24. int main() {
  25. derived_once_more dom;
  26. derived dd;
  27. dom.foo();
  28. dd.foo();
  29. return 0;
  30. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
PP7derived
PP7derived