fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class A
  5. {
  6. public:
  7. A()
  8. {
  9. cout << "1";
  10. }
  11. virtual ~A()
  12. {
  13. cout << "2";
  14. }
  15. };
  16.  
  17. class B:public A
  18. {
  19. public:
  20. B()
  21. {
  22. cout << "3";
  23. }
  24. ~B()
  25. {
  26. cout << "4";
  27. }
  28. };
  29.  
  30. int main()
  31. {
  32. A* obj;
  33. obj = new B;
  34. delete obj;
  35. obj = new A;
  36. delete obj;
  37. return 0;
  38. }
Success #stdin #stdout 0s 4240KB
stdin
Standard input is empty
stdout
134212