Overloading/Inheritance issue

Charles D Hixson charleshixsn at earthlink.net
Sat Aug 4 16:08:22 PDT 2007


Derek Parnell wrote:
> On Wed, 01 Aug 2007 16:47:12 -0400, Steve Schveighoffer wrote:
> 
>> I am wondering if the following behavior is intentional and if so, why. 
> 
> This is intentional and is due to D's simplistic lookup rules. Basically, D
> will look for a matching signature only in the class it self and not in any
> parent classes (its a little more complex than this but ...)
> 
> To 'fix' this situation you need to explicitly identify methods from parent
> classes that you wish to access from objects of the child class. This is
> done using an alias statement.
> 
> Add "alias X.foo foo;" to your class definition of Y.
> 
> class Y : X
> {
>   alias X.foo foo; // pulls in class X's foo name into this scope.
>   public int foo(int y)
>   {
>     return 3;
>   }
> }
> 
> Now it will compile and run.
> 
Well if you're going to make that kind of a requirement, why 
not allow multiple inheritance?  It would seem to resolve all 
the problems with "ambiguity in multiple paths of implementation".

(Also, it would be well if this were prominently documented. 
You did a very clear job, so copying that would be all that's 
necessary.  File it under inheritance.)



More information about the Digitalmars-d mailing list