fork download
  1. #include <cstdio>
  2.  
  3. class CBase
  4. {
  5. public:
  6. CBase()
  7. {
  8. printf("CBase::CBase()\n");
  9. }
  10. virtual ~CBase()
  11. {
  12. printf("CBase::~CBase()\n");
  13. this->Destroy();
  14. }
  15. virtual void Destroy()
  16. {
  17. printf("CBase::Destroy()\n");
  18. }
  19. };
  20.  
  21. class CChild : public CBase
  22. {
  23. public:
  24. CChild()
  25. {
  26. printf("CChild::CChild()\n");
  27. }
  28. virtual ~CChild()
  29. {
  30. printf("CChild::~CChild()\n");
  31. }
  32. virtual void Destroy()
  33. {
  34. printf("CChild::Destroy()\n");
  35. }
  36. };
  37.  
  38. int main()
  39. {
  40. printf("a\n");
  41. CChild a;
  42. printf("b\n");
  43. CBase* b = new CChild;
  44. printf("delete b\n");
  45. delete b;
  46. printf("delete a\n");
  47. return 0;
  48. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
a
CBase::CBase()
CChild::CChild()
b
CBase::CBase()
CChild::CChild()
delete b
CChild::~CChild()
CBase::~CBase()
CBase::Destroy()
delete a
CChild::~CChild()
CBase::~CBase()
CBase::Destroy()