polymorphism: overloading vs. overriding
Bruno Medeiros
brunodomedeirosATgmail at SPAM.com
Sun May 7 04:09:32 PDT 2006
Mike Parker wrote:
> Markus Kranz wrote:
>> Following the rule of last surprise: wouldn't it be desirable if the
>> output of
>> the following program would be:
>>
>> Bar.doIt()
>> Bar.doIt(Bar)
>>
>> The actual output
>>
>> Bar.doIt()
>> Foo.doIt(Foo)
>>
>> at least for me is a little bit surprising since the best matching
>> function
>> seems to be Bar.doIt(Bar).
>> As overriding with covariant return types is supported it seems a bit
>> unnatural
>> to me that overriding with covariant arguments does not work.
>>
>> Instead of doing overload resolution before virtual function
>> resolution (what
>> seems to be done now) an implementation of 'covariant arguments'
>> theoretically
>> could be as simple as reversing the order of resolution.
>>
>> What do you think?
>
> This line is the key:
>
> Foo foo = new Bar();
>
> foo is an instance of Foo, not an instance of Bar,
No, that is wrong, foo *is* an instance of Bar. (yet, it's type contract
is only that it is a Foo)
--
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list