Thomas Lenz
12/16/2008 9:58:00 AM
am Dienstag 16 Dezember 2008 09:16 schrieb Juan Antonio Zaratiegui
Vallecillo:
> Thomas Lenz escribió:
>> Hi group,
>>
>> just curious: assuming i have a base class B with virtual functions and
>> other classes derived from B:
>>
>> does this result in a vtbl / vptr's per class, or per object ?
>>
>>
>> thanks, Thomas
>>
>
> The information that belongs to the class will exits per class. *If*
> this is implemented as a vtbl, there will be a vtbl per class.
>
> Each object needs to know the class it belongs to, and thus it will
> contain some way to do that. *If* this is implemented as a vptr, there
> will be a vptr per object.
>
> There may be other ways to solve virtuality problems, but always "...
> give to Caesar what is Caesar's , and to God what is God's". That is,
> information belonging to a class will exist in a per-class basis
> (similar to an static data member), information belonging to an object
> will exist within the object (similar to a non-static data member)
>
> Best regards,
>
> Zara
ok, so it's one vtbl per class.
Just to make sure i got the vptr issue right: my understanding so far is
that vptrs point to the right virtual function, based on the "real" object
type, not on the type of the pointer/reference that points/references to
the object. So is there one vptr per object PER (VIRTUAL) FUNCTION? or do
compilers (assuming they use the vptr approach) somehow manage to do this
with just one vptr per object (only)?
Thanks in advance,
Thomas