Memory layout of an object with multiple inheritance

Discussion in 'C++' started by stasgrom@gmail.com, Oct 8, 2006.

  1. Guest

    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.
     
    , Oct 8, 2006
    #1
    1. Advertising

  2. wrote:

    > 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
     
    Thomas Tutone, Oct 8, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anargyros L. Papadopoulos

    inheritance and memory layout

    Anargyros L. Papadopoulos, Mar 8, 2005, in forum: C++
    Replies:
    2
    Views:
    481
  2. Replies:
    1
    Views:
    588
    John Timney \(MVP\)
    Jun 19, 2006
  3. Edsko de Vries
    Replies:
    0
    Views:
    941
    Edsko de Vries
    Jan 9, 2006
  4. Ge Chunyuan
    Replies:
    0
    Views:
    966
    Ge Chunyuan
    Jul 23, 2007
  5. Rouslan Korneychuk
    Replies:
    8
    Views:
    604
    Rouslan Korneychuk
    Feb 10, 2011
Loading...

Share This Page