Hijacking

Walter Bright newshound1 at digitalmars.com
Fri Aug 10 23:32:33 PDT 2007


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.



More information about the Digitalmars-d mailing list