private is a keyword for setting class access level to private (the other access levels are public and protected) or for private inheritance.
A class created with the keyword class has a private access level by default, a class created by the keyword struct has public access level by default.
- Declare member variables private [1-5], except in PODs [4]
- Prefer private members for implementation details [6]
- Making the data members of a class private and the member functions of the class public facilitates debugging [7]
- An attempt by a function, which is not a member of a particular class (or a friend of that class) to access a private member of that class is a compilation error [8]
- John Lakos. Large-Scale C++ Software Design. 1996. ISBN: 0-201-63362-0. Section D.2: Major Design Rules, Chapter 2, page 820: 'Keep class data members private'
- Scott Meyers. Effective C++ (3rd edition). ISBN: 0-321-33487-6. Item 22: Declare data members private.
- Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Chapter 11: 'Hide information'.
- Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Chapter 41: 'Make data members private, except in behaviourless aggregates (C-style structs).
- John Lakos. Large-Scale C++ Software Design. 1996. ISBN: 0-201-63362-0.
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 20.7. Advice. page 611: '[10] Prefer private members for implementation details'
- Paul Deitel, Harvey Deitel. C++11 for programmers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 3.4, Error Prevention Tip 3.1. page 47: 'Making the data members of a class private and the member functions of the class public facilitates debugging because problems with data manipulations are localized to either the class's member functions or the friends of the class'
- Paul Deitel, Harvey Deitel. C++11 for programmers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 3.4, Common Programming Error 3.2. page 47: 'An attempt by a function, which is not a member of a particular class (or a friend of that class) to access a private member of that class is a compilation error.'