contravariant argument types: wanna?
"Jérôme M. Berger"
jeberger at free.fr
Wed Sep 23 13:40:58 PDT 2009
Andrei Alexandrescu wrote:
> Walter Bright wrote:
>> Andrei Alexandrescu wrote:
>>> Today D does not support contravariant arguments, but Walter told me
>>> once he'd be quite willing to implement them. It is definitely the
>>> right thing to do, but Walter would want to see a compelling example
>>> before getting to work.
>>
>> The stumbling block to contravariant parameters (not arguments) is how
>> it throws a monkey wrench into the overloading rules. The problem is
>> deciding if a function overrides or overloads, when its parameter
>> types are different.
>>
>> The current rule is simple: if the parameter types are identical, it
>> overrides. If they are not identical, it overloads.
>
> I don't see that as a huge problem. First off, right now the override
> keyword is required (and for good reason, I might add). Second, the new
> rule is simple: if the overriding function can be called with the
> overriden function's arguments, it is overriding it. True, things get
> more complicated when the base class also defines a corresponding overload:
>
> class A {
> void fun(A);
> void fun(B);
> }
>
> class B : A {
> override void fun(A);
> }
>
This is poor design since it involves crossed dependencies. The
ancestor should never be aware of the derived classes. Therefore, I
vote for it to be an error.
Jerome
--
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20090923/20d1be43/attachment.pgp>
More information about the Digitalmars-d
mailing list