C++: Applying public, private and protected keywords to the base class itself

This entry is part 43 of 61 in the series C++

We have looked at applying the 3 keywords to data members and functions.

And as mentioned, we we can apply the 3 keywords to the base class itself.

Access control using public, private and protected helps prevent you from using objects in ways they were not intended to be used.

When preceding the name of a base class, the public keyword specifies that all members of the base class (except, of course, for constructors) are inherited as they are, with their level of member access preserved.

So private members are inherited as private members, public members are inherited as public members, and so on.

The private keyword specifies that members of the base class are inherited, but all of them—whether public, private, or protected—become private in the subclass.

With the protected keyword access level, private and protected members of the base class are inherited as is, but public members become protected in the subclass.

I will illustrate it with an example on the next post.

Series Navigation<< C++: Public, private and protected
C++: Inheritance >>
Posted in