www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Interface inheritance

reply Mandeep Singh Brar <mandeep brars.co.in> writes:
The following code does not compile.

import std.stdio;
interface A {
        public void a(int l);
}
class ACl:A {
        public void a(int l) {
                writeln("Hello a");
        }
}

interface B: A {
        public void a(string l, int k);
}

class BCl: ACl, B {
        public void a(string l, int k) {
                writeln("Hello B.a", l, k);
        }
}

int main() {
        B b = new BCl();
        b.a(1);
        return 0;
}

However casting B to A like (cast(A)b).a(1); makes it work.

Regards
Mandeep
Dec 12 2010
parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Mandeep Singh Brar <mandeep brars.co.in> wrote:

 The following code does not compile.

 import std.stdio;
 interface A {
         public void a(int l);
 }
 class ACl:A {
         public void a(int l) {
                 writeln("Hello a");
         }
 }

 interface B: A {
         public void a(string l, int k);
 }

 class BCl: ACl, B {
         public void a(string l, int k) {
                 writeln("Hello B.a", l, k);
         }
 }

 int main() {
         B b = new BCl();
         b.a(1);
         return 0;
 }

 However casting B to A like (cast(A)b).a(1); makes it work.

 Regards
 Mandeep
http://d.puremagic.com/issues/enter_bug.cgi Please file the bug here. -- Simen
Dec 12 2010