fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class LeakyBase{
  6. public:
  7. ~LeakyBase(){}
  8. };
  9.  
  10. class PluggedBase{
  11. public:
  12. virtual ~PluggedBase(){}
  13. };
  14.  
  15. class LeakyDerived : public LeakyBase{
  16. public:
  17. LeakyDerived() { cout << "LeakyDerived()" << endl; }
  18. ~LeakyDerived() { cout << "~LeakyDerived()" << endl; }
  19. };
  20.  
  21. class PluggedDerived : public PluggedBase{
  22. public:
  23. PluggedDerived() { cout << "PublicDerived()" << endl; }
  24. ~PluggedDerived() { cout << "~PluggedDerived()" << endl; }
  25. };
  26.  
  27. int main()
  28. {
  29. LeakyBase * l = new LeakyDerived;
  30. PluggedBase * p = new PluggedDerived;
  31.  
  32. delete l;
  33. delete p;
  34. }
  35.  
Success #stdin #stdout 0.01s 2812KB
stdin
Standard input is empty
stdout
LeakyDerived()
PublicDerived()
~PluggedDerived()