Re: vtbl inheritance
On Jan 31, 8:04 pm, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
James Kanze <james.ka...@gmail.com> wrote
innews:03bb4d45-72ff-4d8d-bee0-ffa1f85f2cce@u6g2000vbh.googlegroups.com:
On Jan 30, 4:29 pm, Leigh Johnston <le...@i42.co.uk> wrote:
On 30/01/2011 16:14, Serve Laurijssen wrote:
[..]
In VC++ the vtable pointer will be in the
RefCounted base sub-object so will not be affected by the memset.
Really? I would have expected that it be in front of the
UnitHeader element, with another vptr in the RefCounted
subclass. (The vptr for CHeader has to point to a different
vtable than that of RefCounted.)
No, it doesn't as vtable is inherited only from one branch of the
multiple inheritance tree. VS2010 keeps the vtable pointer in the
RefCounted subobject and fills it in with CHeader virtual function
pointers (destructor only in this example).
So I see. But to do this, it rearranges the object, so that the
CHeader subobject has the same address as the most derived
object. Without this rearrangement (which is perfectly valid),
it would need a vptr for the CHeader, and another for the most
derived object, since code will access the vptr from the address
it has.
Even if the compiler decided to add another vtable pointer somewhere in
the object this would not affect memset of the UnitHeader POD object in
any way.
This is where I'm not sure. I don't think that a base object is
required to occupy sizeof(Base) bytes; it certainly isn't if the
base is empty, and in general, the wording of sizeof seems to
suggest that it might not be valid when used on base classes.
--
James Kanze