Will there be any difference if we inherit the class first or interface in C++ ?
class
interface
C++
Example:
class A : public IAbstract, public ClassB { }; class A : public ClassB, public IAbstract { };
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 ------
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.
ClassB
IAbstract
(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