Advertisement
robn

Untitled

Jul 28th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. class Thing {
  4. public:
  5.     ~Thing() {
  6.         printf("destroying Thing\n");
  7.     }
  8. };
  9.  
  10. class Base {
  11. public:
  12.     // without this destructor, Derived is never cleaned up and
  13.     // Thing::~Thing() is never called
  14.     virtual ~Base() {}
  15. };
  16.  
  17. class Derived : public Base {
  18. public:
  19.     Thing thing;
  20. };
  21.  
  22. int main(int argc, char **argv) {
  23.     Base *b = new Derived;
  24.     delete b;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement