I have a class structure of three classes where two of them are base classes of the third, like this:
class A {
};
class B {
};
class C : public A, public B {
};
When an instance of C
is to be destroyed, in which order are the base classes A
and B
destroyed? Are there any rules for this?
There are rules (C++11 §12.4):
The construction order is (§12.6.2/10):
So in simple cases, base constructors are called in the order in which the classes are listed in the declaration, and destructors run in reverse of that order.