Suggestion: Allow Multiple Inheritance and still preserver super() functionality

Jim Gadrow MakariVerslund at gmail.com
Thu Mar 6 08:47:47 PST 2008


Now, maybe I'm just ignorant because I've never written a compiler, but why isn't it possible to allow for something like the example following in the language?

I will first state that I don't like the super() function because I don't believe the keyword 'super' very clearly identifies what is going on. wouldn't parent() have been more suitable?

Anyways, the example:

import std.stdio;

interface A {
    void myFoo ();
}

interface B {
    void myBar ();
}

class C : A
{
    this ()
    {
        writefln ("Constructing a C...");
    }

    void myFoo ()
    {
        writefln ("I've been foo'd!");
    }
}

class D : B
{
    this ()
    {
        writefln ("Constructing a D...");
    }

    void myBar ()
    {
        writefln ("I've been bar'd!");
    }
}

class E : C, D
{
    this ()
    {
        parent.C ();    //Calls constructor of parent class C
        parent.D ();    //Calls constructor of parent class D
    }

    void myFooBar ()
    {
        myFoo ();
        myBar ();
    }
}

void main ()
{
    E myClass;
    myClass.myFooBar ();
}

Running the program should output:
Constructing a C...
Constructing a D...
I've been foo'd!
I've been bar'd!

Obviously, the same rule would apply for inheriting multiple classes as for inheriting multiple interfaces in that something like:

class D : C, C

Would cause a compile error.



More information about the Digitalmars-d mailing list