vtbl inheritance

P

Paul

Leigh Johnston said:
You have so much lulz when not being obnoxious that I am surprised I do
not *facepalm*.
Don't know what this nonsense is supposed to mean. It appears to confirm the
fact that you have very low brain capacity.
 
P

Paul

Leigh Johnston said:
innews:03bb4d45-72ff-4d8d-bee0- (e-mail address removed):
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.

I'm not sure what you mean here - CHeader is not a subobject, it is the
most derived class in this example. And in the VStudio debugger I do not
see it has rearranged anything, all subobjects are in the same order as
appearing in the code. In particular, the CHeader vtable pointer is
placed in the middle of the CHeader object.

Don't put too much faith in the debugger; try examining the memory
directly rather than how it displays the object members.
WTF do you know about Objects esp. obj's that have any kinda functions?
 
P

Paul

Paul said:
Leigh Johnston said:
(e-mail address removed):

(e-mail address removed):
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.

I'm not sure what you mean here - CHeader is not a subobject, it is the
most derived class in this example. And in the VStudio debugger I do not
see it has rearranged anything, all subobjects are in the same order as
appearing in the code. In particular, the CHeader vtable pointer is
placed in the middle of the CHeader object.

Don't put too much faith in the debugger; try examining the memory
directly rather than how it displays the object members.
WTF do you know about Objects esp. obj's that have any kinda functions?
Obviously not a freakin lot , esp since you think objects don't have
functions.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top