fork download
  1. #include<iostream>
  2.  
  3. struct test
  4. {
  5. virtual void print() { std::cout << "I'm the parent" << std::endl; }
  6. };
  7.  
  8. struct derived : public test
  9. {
  10. virtual void print() { std::cout << "I'm the derived" << std::endl; }
  11. };
  12.  
  13. int main()
  14. {
  15. test* a = new test;
  16. test* b = new derived;
  17.  
  18. a->print();
  19. b->print();
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
I'm the parent
I'm the derived