Overloading/Inheritance issue

Derek Parnell derek at psych.ward
Wed Aug 1 13:56:04 PDT 2007


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.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list