Access levels

So far, we have seen two access specifiers for class members: public and private. Members declared in the public section can be accessed by code in the class and by code outside the class either on an object or if the member is static, using the class name. Members declared in the private section can only be accessed by other members in the same class. A derived class can access the private members of the base class but not the private members. There is a third type of member access: protected. Members declared in the protected section can be accessed by methods in the same class or by methods in any derived class and by friends, but not by external code:

    class base     {     protected:         void test();     };   class derived : public ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.