www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5344] New: Interface Inheritance Problem

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5344

           Summary: Interface Inheritance Problem
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mandeep brars.co.in



09:32:28 PST ---
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: public 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 changing the second line of main() to (cast(A)b).a(1) makes it work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 12 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5344


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



10:17:49 PST ---
If I'm not mistaked:
B b = new BCl();

means the object b has a static type B, and the dynamic type BCl. Which means
you can only call methods defined by the B interface. This is probably
discussed more in TDPL, but I'd have to check it again because I'm not sure..

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 19 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5344




10:18:32 PST ---
Oh I see the problem now, B inherits from A, I missed that line.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 19 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5344




10:28:32 PST ---
Yeah the only way this compiles is if you use the A type:
A b = new BCl();
b.a(1);

I don't see why using a B object wouldn't work. Bug, i guess..

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 19 2010