access subclass functions

Saaa empty at needmail.com
Thu Nov 20 19:59:48 PST 2008


> Informally, "virtual" means "can be overridden". It only applies to
> methods on classes. This definition is informal and ambiguous.
virtual functions are slowers because you have the extra step of
vtable, right?
How much of a difference can I expect?
Because it doesn't look like a lot of work: just one single table lookup.

>
> According to __traits in d2, "virtual" means "might have a vtbl entry". A 
> vtbl is a list of function pointers corresponding to the methods of a 
> class. Each instance of that class has a pointer to the same list.
Ok
> Virtual dispatch just consists of pointing to a different vtbl with a 
> different function in that slot.
Virtual dispatch?


> Anyway, the __traits definition maps to the following lemmas[1]:
> - static is not virtual
- there is only one function shared with between all the object.

> - template is not virtual
- I've never used these

> - private is not virtual
Ok

>
> On the other hand, final functions are virtual. If a final function does 
> not override a virtual function, the compiler can turn it into a free 
> function if that's more efficient. Or maybe not. If a final function 
> overrides a virtual function, it will certainly end up in the class vtbl.
I have never used final either :)

>
> Final functions are a bit questionable. If they override a virtual method 
> in a base class, they should certainly be considered virtual, but you also 
> sometimes need to know whether you can override a function. That is when 
> it's not final and it is virtual.
When I need to know whether I can override it, it becomes virtual?
How does the compiler know that I want that?

>
>
> [1] It's a bit of a stretch to grant them this name, but if life gives you 
> lemmas, make lemma-ade.
:) 




More information about the Digitalmars-d-learn mailing list