A private member is a class member that outside code cannot access directly. In C++, private member variables store hidden state, while private member functions often provide internal helper behavior. The class exposes only the public operations that other code needs. section 5.0 section 1.8
Use access levels to control which code may depend on an implementation:
- public members form the class interface and can be accessed by any code. section 1.8
- private members are accessible only by member functions of their defining class. section 5.1 section 1.8
- protected members are accessible to subclass member functions but remain hidden from other code. section 5.1
Private members support encapsulation and the Principle of Least Knowledge. A Book class can keep title and author private while offering public access without exposing whether those values are stored directly or obtained dynamically. Because clients cannot depend on the hidden implementation, the class can change internally with fewer effects on other code. section 5.0 section 5.1
Mammal state and helper behavior
A Mammal class keeps weight and height private and exposes const getter functions. Its private snore() function supports the protected sleep() function, which subclasses may use without seeing the internal snoring implementation. Human and Cat then keep their own state and helper functions private while implementing public behavior such as eat() and perform(). section 5.8
Figure 4.2 Possible UML class diagrams for class Catalogue that include different amounts of information. A plus sign (+) indicates public, and a minus sign (-) indicates private. How much information to include in a class diagram depends on whether the diagram is in high-level or low-level design documentation of the application.
Use the UML notation to identify access: a minus sign marks private members, a plus sign marks public members, and a hashtag marks protected members. section 4.3











