You do not need multiple inheritance in this particular case: If class C
inherits only from B
, any instance of class C
can be cast to both B
and A
; since B
already derives from A
, C
doesn't need to be derived from A
again:
class A { ... }
class B : A { ... }
class C : B { ... }
...
C c = new C();
B bc = (B)c; // <-- will work just fine without multiple inheritance
A ac = (A)c; // <-- ditto
(As others have already said, if you need something akin to multiple inheritance, use interfaces, since a class can implement as many of those as you want.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…