Variable offset and multi inheritance

B

bergel

Hello,

Regarding the variable layout with multi inheritance, I looked into a
couple of C++ books but I was not able to find a descent answer.
Let assume I have the following:
class A{
int x;
}
int A::getX(){ return x;}

class B{
int y;
}
int B::getY(){ return y;}

class C: virtual A, virtual B {
}

In A the offset of x is 0. Same thing for B, the offset of y is 0.
But what is the variable layout of C?
If x'offset = 0 and y's offset = 1, what's happen with the getY()
method ? Is it duplicated to take the new offset into account ? Or is
there any dynamic lookup of variables ?

Cheers,
Alexandre
 
A

Artie Gold

bergel said:
Hello,

Regarding the variable layout with multi inheritance, I looked into a
couple of C++ books but I was not able to find a descent answer.
Let assume I have the following:
class A{
int x;
}
int A::getX(){ return x;}

No such function has been declared.
class B{
int y;
}
int B::getY(){ return y;} Similarly.

class C: virtual A, virtual B {
}

In A the offset of x is 0. Same thing for B, the offset of y is 0.
But what is the variable layout of C?
If x'offset = 0 and y's offset = 1, what's happen with the getY()
method ? Is it duplicated to take the new offset into account ? Or is
there any dynamic lookup of variables ?

Cheers,
Alexandre
Important question: Why do you care?

This is a question about `under the hood' implementation, not one about
the C++ language itself.

--ag
 

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
474,297
Messages
2,571,536
Members
48,284
Latest member
alphabetsalphabets

Latest Threads

Top