fork(1) download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. struct foo{
  5. public:
  6. virtual ~foo(){}
  7. };
  8.  
  9. struct bar : foo{};
  10.  
  11. int main() {
  12. bar *pbar = new bar;
  13. foo *pfoo = pbar;
  14. std::cout << typeid(foo).name() << std::endl;
  15. std::cout << typeid(bar).name() << std::endl;
  16. std::cout << typeid(*pfoo).name() << std::endl;
  17. std::cout << typeid(*pbar).name() << std::endl;
  18. delete pbar;
  19. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
3foo
3bar
3bar
3bar