Private inheritance definition: all the Members inherited from private will become private attributes in derived.
Application Scenario: when a person who wants to become a derived class wants to access a protected component that wants to become a base class,
Or private inheritance can be used to redefine one or more virtual functions.
Knowledge point:
Private inheritance means that only the implementation part is inherited, and the interface part should be omitted.
If the inheritance relationship between classes is private, the compiler will not automatically convert a derived class object to a base class object,
Such conversions may cause errors. Remember, private inheritance is simply an implementation technology.
Replace private inheritance with compound inheritance. Because combination can avoid redefinition of virtual functions.
Example:
Class Widget: public Timer
{
Private:
Virtual void onTick () const; // view Widget data.
};
// Composite implementation
Class Widget
{
Private:
Class WidgetTimer: public Timer
{
Public:
Virtual void onTick () const; // view Widget data.
};
WidgetTimer timer;
};