Hijacking

Regan Heath regan at netmail.co.nz
Sat Aug 11 03:06:43 PDT 2007


Walter Bright wrote:
> Kristian Kilpi wrote:
>>
>> The old aliasing trick will still cause problems.
>>
>> (The 'override' keyword won't solve the problem in the following case.)
>>
>>   class A {
>>     void foo(int);
>>     void foo(long);
>>   }
>>
>>   class B : A {
>>     alias A.foo foo;
>>     override void foo(int);
>>   }
>>
>>   void bar(B b) {
>>     short val = 1;
>>
>>     b.foo(val);  //calls 'foo(int)'
>>   }
>>
>> Now 'foo(short)' is added to 'A':
>>
>>   void bar(B b) {
>>     short val = 1;
>>
>>     b.foo(val);  //calls 'foo(short)'
>>   }
> 
> I don't think this is a problem, because the B author explicitly and 
> deliberately opened the door to this, therefore he is taking 
> responsibility for it.

Yes and no.

At the time the author wrote "alias A.foo foo;" they were allowing void 
foo(long), not void foo(short).

Yes, they still "opened the door to this" because D's current behaviour 
is to pull all overloads past/present/future.

Perhaps being able to specify overloads exactly would in some cases be 
of benefit, eg.

alias A.foo(long) foo;

Regan



More information about the Digitalmars-d mailing list