I want to inherit from class A, but A's destructor is not virtual and I cannot modify A's definition. How to avoid the following case?
struct A
{
A()
: a(new char[8])
{}
~A()
{
delete[] a;
}
char* a;
}
struct B : A
{
B()
: A(), b(new char[8])
{}
~B()
{
delete[] b;
}
char* b;
};
int main()
{
A* p_a = new B;
delete p_a; // How to avoid such a dangerous deletion?
}