[LC++]virtual functions

Paul Gearon gearon at ieee.org
Sun Oct 31 16:36:01 UTC 2004


On 29/10/2004, at 8:33 PM, Adriano dos Santos Fernandes wrote:

> Paul Gearon wrote:
>
>> If not for the virtual table then a pointer of type base* would 
>> always find the base::print() method, even if the object is of type 
>> "derived".  Calling a method on an object without a virtual table 
>> just goes to some fixed offset from the start of the object to find 
>> the method.
>
> Wrong. The method is called as a normal function (resolved by the 
> linker).
> A class that don't have virtual functions is as a C struct, it don't 
> have "hide" variables.

Sorry.  You're quite correct here.  If things were done that way then 
you'd end up with the same code being repeated for every object of the 
same type.

Not sure what I was thinking when I wrote that  :-}

Regards,
Paul Gearon

Software Engineer
Tucana Technologies
http://www.tucanatech.com

Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum
immane mittam.
(Translation from latin: "I have a catapult. Give me all the money,
or I will fling an enormous rock at your head.")





More information about the tuxCPProgramming mailing list