Mode of Inheritance
A base class can be derived in three different modes: public, protected and private. Deriving using public is is-a-relationship. But protected/private inheritance is not is-arelationship. With this, we will get only data and functionality of the base class, but the functionality is hidden, that is we get only implementation, not interface for the user of the class. So, it's called as implementation inheritance. (Public inheritance is called as interface inheritance). And the user of the class can't be able to treat it as instance of base class. So, it will be kind of has-a, that is composition.
In protected/private inheritance, all public members will be private in derived class. If we want them to be visible for the user, we can keep those base class public function names under public section of the derived class. By specifying name of one overloaded function of base class in this section, all versions of overloaded functions will be visible in derived class.
But we can't increase the visibility of private/protected members of base in derived class.
Most of the time, its better to use composition compare to private/protected inheritance as both serve the same. In case of protected/private inheritance there will be more complications with run time type identification.
Composition is generally used when we want the features of an existing class inside our new class, but not its interface, which is just like private/protected inheritance. Use private inheritance, only if you want to produce part of the same interfaces as the base class and disallow is-a relationship.





