Junior — Senior
Generate a situation causing undefined behavior when deleting through a base pointer
livecode
Task condition
It is necessary to show an example where an object of a derived class is deleted through a pointer to an abstract base class, which does not declare its destructor as virtual. In such a case, undefined behavior occurs or an exception is thrown.
struct A {
virtual void foo() = 0;
// destructor is not virtual
};
struct B : A {
~B(); // should be called correctly
};