fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base
  5. {
  6. virtual void method() {std::cout << "from Base" << std::endl;}
  7. public:
  8. virtual ~Base() {method();}
  9. void baseMethod() {method();}
  10. };
  11.  
  12. class A : public Base
  13. {
  14. void method() {std::cout << "from A" << std::endl;}
  15. public:
  16. ~A() {method();}
  17. };
  18.  
  19. int main(void)
  20. {
  21. Base* base = new A;
  22. base->baseMethod();
  23. delete base;
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 5392KB
stdin
Standard input is empty
stdout
from A
from A
from Base