fork download
  1. #include <iostream>
  2. using namespace std;
  3. class B
  4. {
  5. public:
  6. virtual void Test() {cout <<"B::Test"<<endl;}; // = 0; makes pure function call crash
  7. void InDirect()
  8. {
  9. Test();
  10. }
  11. B(){ /*InDirect();*/ }
  12. virtual ~B(){cout<<"~B"<<endl; InDirect();}
  13. };
  14. class BB : public B
  15. {
  16. public:
  17. //void Test() override
  18. //{ cout <<"BB::Test"<<endl; }
  19. ~BB(){cout<<"~BB"<<endl; InDirect();}
  20.  
  21. };
  22. class BBB : public BB
  23. {
  24. public:
  25. void Test() override
  26. { cout <<"BBB::Test"<<endl; }
  27. ~BBB(){cout<<"~BBB"<<endl;}
  28. };
  29. int main() {
  30. B* ptr = new BBB;
  31. delete ptr;
  32. return 0;
  33. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
~BBB
~BB
B::Test
~B
B::Test