Why can't I ignore inheritacne from B here - or is there a way to make this possible?
Because classes can only decide how to construct their direct subobject. The direct subobject for A
is B
and for B
is C
. The B
object needs to be constructed too, you can't bypass it.
The error you got, basically complains about this.
Defining A as follows does not work, here compiler complains C is already a base class of A:
class A : B,C
With:
class A : B, C
you are actually declaring a private multiple inheritance. And since you said B
has already a subobject (inherits from) C
, the compiler is complaining that inheriting from C
in A
is useless.
But please remember to always specify the private
/protected
/public
kind of inheritance so that you avoid confusion. By default the inheritance for class
es is private
and for struct
s is public
. So the above code corresponds to:
class A : private B, private C