class A { int *a; public: A(){ a = new int; } virtual ~A(){ del(); } virtual void del(){ if(a){ delete a; a = NULL; } } }; class B:public A { int *b; public: B(){ b= new int; } virtual ~B(){} void del(){ if(b){ delete b; b = NULL; } } }; int main() { B b; A *a = new B; delete a; }