Suggestion: Allow Multiple Inheritance and still preserver super() functionality
Steven Schveighoffer
schveiguy at yahoo.com
Fri Mar 7 11:40:25 PST 2008
"Jim Gadrow" wrote
> Thank you all for your responses. They have illuminated why
> multiple-inheritance is less than optimal in terms of language
> implementation.
>
> The only thing I will miss is the ability to allow a class to inherit
> fields from multiple classes if it 'is' related to both classes. But, I
> suppose I could do that via mixin, it just seems to add work-around code
> but at least now I know the rationale behind it.
There are ways to do it with inner classes (without solving the diamond
problem):
class A
{
void a() {}
}
class B
{
void b() {}
}
class C : A
{
void a() {}
class innerB : B
{
void b() { // can call a() or access C's members}
C opCast() { return this.outer; }
}
// make it seamless
private innerB _innerB;
void b() { _innerB.b() }
B opCast() { return _innerB;}
}
This really is just exposing the ugliness that compilers that support
multiple inheritance hide :)
But I'd say before doing something like this, the best thing to do is to try
and use interfaces and encapsulation.
-Steve
More information about the Digitalmars-d
mailing list