polymorphism: overloading vs. overriding

Markus Kranz markus_kranz at gmx.net
Sun May 7 06:34:46 PDT 2006


In article <e3kp8d$31ag$1 at digitaldaemon.com>, Bruno Medeiros says...
>
>Bruno Medeiros wrote:
>> No, it's not unnatural. For a function to override another, the return 
>> type must be covariant, but the parameters must be contravariant.
>> It's quite natural to be this way, in fact, it's the only correct way 
>> (other than invariant parameters).
>
>Whoa, I forgot to mention: D doesn't support contravariant parameters, 
>only covariant return types (in other words, a covariant parameter will 
>create a new overload, and not an override). I don't know why I got the 
>idea that D supported that.

So the actual state is

(1) the scope of overload resolution is the current class (and optionally
superclasses using alias)
(2) the scope of virtual function resolution is the current class and
'childwards'

Overloading and overriding on their own seem to be simple concepts.
It remains the question: as in D is it enough to implement both concepts
separately although they are strongly related?
(In both concepts we deal with multiple functions having a common name and
search for the 'best' matching instance.)

Regards,
Markus





More information about the Digitalmars-d mailing list