Proposition for change in D regarding Inheriting overloaded methods

Sean Kelly sean at f4.ca
Tue Aug 7 16:01:02 PDT 2007


Regan Heath wrote:
> Walter Bright wrote:
>> The next update of the compiler will throw a runtime exception for 
>> this case.
> 
> So, in this case:
> 
> class B
> {    long x;
>      void set(long i) { x = i; }
>     void set(int i) { x = i; }
>     long squareIt() { return x * x; }
> }
> class D : B
> {
>     long square;
>     void set(long i) { B.set(i); square = x * x; }
>     long squareIt() { return square; }
> }
> long foo(B b)
> {
>     b.set(3);
>     return b.squareIt();
> }
> 
> when the call to b.set(3) is made you insert a runtime check which looks 
> for methods called 'set' in <actual type of object>, if none of them 
> take a <insert types of parameters> you throw an exception.

I assume the compiler would not throw an exception for the following case?

class D : B
{
     long square;
     alias B.set set;
     void set(long i) { B.set(i); square = x * x; }
     long squareIt() { return square; }
}


Sean



More information about the Digitalmars-d mailing list