This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: sizeof with virtual inheritance


Hi Adrian,

>I would like to know why the size of class objects grows when virtual inheritance is involved.

The structure has extra bookkeeping information to keep track.

For example, if you have multiple inheritance of:
foo : bar
baz : bar
quux : foo, baz

The memory layout of quux is going to be:
bar
foo
baz
quux

If you pass a quux to something that expects a baz, that routine would expect:
bar
baz

...it wouldn't expect a "foo" stuck in the middle.

The extra "behind the scenes" bookkeeping information is used to take care of that situation.

I do not think that it is a "onevtable" (whatever that is) related issue.

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]