samedi 28 janvier 2017

How do I ensure the destruction of a parent instance member?

Consider these two classes in C++11:

class A
{
    ArbitraryClass someInstance;
};

class B : public A
{

};

And consider I use B as such:

B *foo = new B;
delete foo;

As I understand, the implicit destructor of A will not be called here.

Is someInstance still destroyed under these circumstances, because it becomes "associated" as a member of B? Or do I need to declare a virtual destructor on A to automatically trigger the member's destruction?

Aucun commentaire:

Enregistrer un commentaire