As I understand it, if you call delete on an interface pointer (or more specifically a base class pointer, pointing to a derived class instance), and that declaration does not have a virtual destructor, then the resulting behaviour is undefined, and the destructor of the derived object does not get invoked.
class ITestInterface
{
public:
virtual void DoStuff() = 0;
}
class Test : public ITestInterface
{
public:
~Test(){};
virtual void DoStuff() {};
}
...
ITestInferface *pThing = new Test();
delete *pThing; // undefined
Typically you either define a virtual destructor for the base class, or declare it private to prevent calling delete on an interface pointer.
If you declare the interface with no vtable
class __declspec(novtable) ITestInterface
{
public:
virtual void DoStuff() = 0;
}
would deleting an object via the interface pointer now be well defined behaviour, and invoke the appropriate destructor? I don't see why it would, but have been told otherwise.