If I have two classes, one inheriting from the other, and the child class only containing functions, will the memory layout be the same for both classes?
e.g.
class Base {
int a,b,c;
};
class Derived: public Base {
// only functions.
};
I've read that the compiler can not reorder data members, and I do not require multiple-inheritance on the Derived
class. Is there any situation where the memory layout will not be the same? (Multiple inheritance may be needed for the Base
class)
|a|b|c|
for the layout ofBase
, and|junk|a|b|c|
for the layout ofDerived
. When youstatic_cast
fromDerived
toBase
, the compiler would adjust the pointer to be right after the junk (that's what happens with MI, for example). There are other requirements that forbid padding at the start, though, so your conclusion is correct, even if from the wrong premises. – Homosexuality