Memory layout of an object with multiple inheritance

S

stasgrom

Guys, I have this situation: the class C is defined as follow:

class C: public A, public B {...};

Now when I create an object of class C, I can see that the compiler (VS
8.0) decides to layout the memory of this object so that the fields of
class B come before the fields of class A. I always thought the layout
is defined by the order of inheritance. Was I wrong?

Thanks.
 
T

Thomas Tutone

Guys, I have this situation: the class C is defined as follow:

class C: public A, public B {...};

Now when I create an object of class C, I can see that the compiler (VS
8.0) decides to layout the memory of this object so that the fields of
class B come before the fields of class A. I always thought the layout
is defined by the order of inheritance. Was I wrong?

Yes, you were wrong. It's implementation defined.

Best regards,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top