Bug or Feature?

leoandru leoandru_member at pathlink.com
Tue Jun 13 14:56:40 PDT 2006


In article <e6n4rl$kkm$1 at digitaldaemon.com>, Frits van Bommel says...
>
>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>


Ok I see then that is just like writing the method signature of Interface A into
B. Is that really necessary? at least I expected interfaces to behave the way
they do in java or C#. hrm not what I expected, after all interface B is not an
override but rather and overloaded version. I wonder what was the reason behind
that design decision? Also here is another problem I ran into when using
interfaces
<code>
interface Foo
{
Object clone();
}

class Bar : Foo
{
Bar clone()
{
return this; 
}

}

void main()
{
Bar b = new Bar();
Bar c = b.clone(); //works fine

Foo f = b;
Foo g = f.clone(); //access violation
}
</code>
that one looks like a bug not able to explain whats wrong here, pardon me if im
missing something I'm still new to this language.

thanks for the replies so far.





More information about the Digitalmars-d mailing list