Overloading/Inheritance issue

Chris Nicholson-Sauls ibisbasenji at gmail.com
Sun Aug 5 23:22:19 PDT 2007


BCS wrote:
> Reply to Chris Nicholson-Sauls,
> 
>> What we really need is a fix for the problem of casting to a Base
>> class "forgetting" overrides.  Maybe a change to how vtbls work?
>> Okay, an example:
>>
>> class Base {
>> int foo () { return 1; }
>> }
>> class Derived : Base {
>> override int foo () { return 2; }
>> }
>> What I'm thinking, is that Derived's copy of Base's vtbl should have
>> the pointer for .foo replaced with a pointer to its override.  That
>> way, when cast to Base the entry still points to Derived's method.
>> Assuming the vtbl is prepared at compile-time, this shouldn't cause
>> any runtime issues... should it?
>>
> 
> Unless I'm totally misreading you, that IS how it works.
> 
> 

Hmm.  I just re-tested this after your reply, and yes it does indeed 
work.  I could swear that it didn't use to, or at least that there was 
some case that caused Base's implementation to be ran.

But since its apparently working right now... yay.  :)

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list