Suppose a class Y publicly inherits a class X. Is it possible for a class Z to privately inherit Y while publicly inheriting X?
To make this clearer, suppose X defines public methods x1 and x2. Y inherits X, overrides x1 and provides a method y. Does C++ allow for a third class Z to subclass Y in such a way that Y‘s implementation of x1 and y are privately available to it, while the outside world only sees it inheriting X publicly, i.e. having only a single public method x2?
Yes, this is called virtual inheritance.
People cannot do
z.y()orz.x1()but they can doz.x2()and can convert aZ*to aX*. However once they do so, they can callconverted->x1()andconverted->x2(), of course.You haven’t said anything about your goal, but it sounds like you really want to keep
Yas a pointer thoughThis looks more familiar to me.