fork download
  1. #include <iostream>
  2.  
  3. class A {
  4. public:
  5. virtual ~A() {
  6. std::cout << "A DESTRUCTOR" << std::endl;
  7. }
  8. };
  9. class B : public A{
  10. public:
  11. virtual ~B() {
  12. std::cout << "B DESTRUCTOR" << std::endl;
  13. }
  14. };
  15. class C : public B{
  16. public:
  17. virtual ~C() {
  18. std::cout << "C DESTRUCTOR" << std::endl;
  19. }
  20. };
  21.  
  22. int main(int argc, char** argv)
  23. {
  24. A * aPtr = new C(); // The cast here is not needed
  25. C * cPtr = new C();
  26.  
  27. delete aPtr;
  28. delete cPtr;
  29. return 0;
  30. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
C DESTRUCTOR
B DESTRUCTOR
A DESTRUCTOR
C DESTRUCTOR
B DESTRUCTOR
A DESTRUCTOR