Multiple inheritance and covariant return types.

Frank Fischer frank.fischer at s2001.tu-chemnitz.de
Thu Aug 9 05:08:56 PDT 2007


Hi,

I have another question on multiple inheritance. The following code does not
work (tested with DMD 1.020 and 2.003)

---
interface A {}

interface B {}

interface AB: A, B {}

abstract class X {
    abstract A func();
}

interface Y {
    B func();
}

class XY: X, Y {
    AB func() { return null; }
}
---
The compiler complains about the line 'AB func() { return null; }':

t.d(38): function t.XY.func incompatible covariant types A() and B()

but I think it should work, because AB is both, an A and a B, so the return
type is covariant with both overridden methods. In fact, the example works
fine, if X is an interface instead of an abstract class.

Is this a bug or is it my mistake?

Thanks,
Frank



More information about the Digitalmars-d-learn mailing list