Function Hijacking article
Walter Bright
newshound1 at digitalmars.com
Thu Oct 18 13:27:15 PDT 2007
Stewart Gordon wrote:
> "Walter Bright" <newshound1 at digitalmars.com> wrote in message
> news:ff7req$28lq$1 at digitalmars.com...
>> Stewart Gordon wrote:
> <snip>
>>> So the compiler generates an override that throws a runtime error?
>>
>> Yes.
>
> I see now. But function.html is out of date - the second example under
> "Function Inheritance and Overriding" is now bogus.
I'll fix that.
> And I noticed that
> the requirement to specify the override attribute is neither implemented
> nor documented under attribute.html - what gives?
It is documented in the function.html and attribute.html.
It is implemented if you add the -w switch.
>
>>> Does it apply to all overloads, or only where potentially compatible
>>> parameter types are involved?
>>
>> It applies to virtual functions that exist in the vtbl[], but are
>> inaccessible via anything typed with the derived class.
>
> But if there's no chance of calling one intending the other, e.g.
>
> class Qwert {
> void yuiop(int i) { writefln("Qwert.yuiop: int %d", i); }
> void yuiop(string s) { writefln("Qwert.yuiop: string %s", s); }
> }
>
> class Asdfg : Qwert {
> override void yuiop(string s) { writefln("Asdfg.yuiop: string %s", s); }
> }
>
> should it still count?
Yes, because Qwert can have a function which calls yuiop(int) with an
Asdfg instance.
More information about the Digitalmars-d-announce
mailing list