fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct A {
  6. virtual ~A() {}
  7. virtual void test() { cout << "A" << endl; }
  8. };
  9. struct B : A {
  10. void test() { cout << "B" << endl; }
  11. };
  12. struct C : B {
  13. C() : ip(new int()) {}
  14. ~C() { delete ip; }
  15. void test() { cout << "C" << *ip << endl; }
  16. int * ip;
  17. };
  18.  
  19. int main() {
  20. A* a = new A;
  21. A* b = new B;
  22. B* c = new C;
  23.  
  24. a->test();
  25. b->test();
  26. c->test();
  27.  
  28. delete a;
  29. delete b;
  30. delete c;
  31. }
  32.  
Success #stdin #stdout 0.01s 2812KB
stdin
Standard input is empty
stdout
A
B
C0