C++ Video: Inheritance - Public, Protected, and Private

Every C++ programmer must have used public inheritance already, but not everyone has used protected or private inheritance. What are they? What's the usage of them, if any?

class yellowdog : private dog {

From: http://cplusplus.com/doc/tutorial/inheritance/

This access specifier limits the most accessible level for the members inherited from the base class: The members with a more accessible level are inherited with this level instead, while the members with an equal or more restrictive access level keep their restrictive level in the derived class.

It means that public and protected members of dog are now private members of yellowdog.

Where is it useful? Let's say that you want to create a wrapper for the std::fstream class. You could choose to inherit from std::fstream. If you don't want the member functions to be available to the outside world, you could inherit it privately.
Last edited on
Topic archived. No new replies allowed.