I've got 3 classes
class A
{
A();
virtual ~A();
}
class B : public A
{
B();
~B();
}
class C
{
void *obj;
C() : obj(nullptr) {}
~C() { if (obj) delete obj; }
}
when I use class C
as a container for any child of class A
and try to delete C
instance. A
, B
destructor is not inveked is it normal? What is the solutuon?
C* instance = new C();
instance.obj = new B();
//Magic
delete instance; // A and B destructor is not called