Reputation: 31
I have an exam coming up in the near future and I'm really stuck on a question that I couldn't find any answers on.
Suppose that a class CI
inherits class Sup
as:
class CI: protected Sup
{};
Why is this not a classifying heritage?
Thanks in advance and I appreciate all help.
Upvotes: 0
Views: 138
Reputation: 10222
In C++, only public inheritance is deemed as real inheritance, which means a subclass will inherit the interface of its superclass(i.e IS-A relationship). A decent inheritance should satisfy Liskov substitution principle.
As for protected/private inheritance, they're actually kind of containment/composition, for a derived class will hide its base class's interface(as protected/private member) and only make use of base class's implementation(i.e. HAS-A or Is-Implemented-In-Terms-Of relationship).
You may refer to this question on SO for better understanding: Why do we actually need Private or Protected inheritance in C++?
That said, protected/private inheritance is an arguable feature in C++, which is abandoned by C++ successors like Java and C#.
Upvotes: 4