Gilson PJ Gilson PJ - 3 months ago 10
C++ Question

Does order of inheritance between class and interface matter?

Will it make any difference whether we inherit the

class
first or
interface
in
C++
?

example:

class A : public IAbstract, public ClassB
{
};

class A : public ClassB, public IAbstract
{
};

Answer

Yes the object layout will be different. Functionally however, it's equivalent.

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

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

And in the second case:

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