Bug or Feature?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Jun 13 12:49:08 PDT 2006


leoandru at gmail.com wrote:
> I started coding in D a few days now but I ran into a few problems, I wasn't
> sure if these were bugs so I didnt make a bug report. the problem is with
> interface inheritance and method signatures It doesn't ssem to work as expected
> and I don't see any documentation saying otherwise.
> 
> interface A
> {
> void method();
> }
> 
> 
> interface B : A
> {

alias A.method method;

> void method(int a);
> }
> 
> 
> class Foo : B
> {

void method()      { writefln("method()"); }
void method(int a) { writefln("method(", a, ")"); }

> }
> 
> 

void main()
{
     B ref = new Foo();
     ref.method();
     ref.method(1);
}
/*
> B ref = new Foo();
> ref.method();   //doesnt compile, requires an argument.
*/
> 
> This works if the method name in interface B is different from A, Im able to
> call method from interface. Am I doing something wrong? I expected this to work.
> I'm using dmd 0.160 compile on winxp. Thanks for any help/replies!

The new method in B hides the one in A.
With the above modifications it should compile and work.

The use of 'alias' here and why it's necessary is explained in (among 
other places) http://www.digitalmars.com/d/function.html, under 
"Function Inheritance and Overriding":

<quote>
However, when doing overload resolution, the functions in the base class 
are not considered:

[...]

To consider the base class's functions in the overload resolution 
process, use an /AliasDeclaration/:

[...]
</quote>



More information about the Digitalmars-d mailing list