Is there an inheritance order between the class and the interface?

Will there be any difference if we inherit the class first or interface in C++ ?

Example:

 class A : public IAbstract, public ClassB { }; class A : public ClassB, public IAbstract { }; 
+5
source share
2 answers

Yes, the layout of the object will be different. Functionally, however, this is equivalent.

In the first case, the layout of the object will look something like this:

 ------ IAbstract members, including vptr ------ Class B members ------ 

And in the second case:

 ------ Class B members ------ IAbstract members, including vptr ------ 
+7
source

the initialization order of direct base classes (i.e. ClassB and IAbstract ) will be different. It is determined by the order of the declaration in the list of base class specifiers.

(my emphasis)

2) Then the direct base classes are initialized in order from left to right , as they appear in this list of basic class specifications

+9
source

All Articles