We have following class hierarchy with virtual inheritance.
Here is the source code for above illustration:
class A {
public:
virtual ~A() { std::cout << "A"; }
};
class B : virtual public A {
public:
~B() { std::cout << "B"; }
};
class C : virtual public A {
public:
~C() { std::cout << "C"; }
};
class D : public B, public C {
public:
~D() { std::cout << "D"; }
};
Note that:
Suppose we create an instance of class D and delete it:
A* aPtr = new D();
delete aPtr;
In what order the defined destructors would be invoked?