CHAPTER 16

image

Access Levels

Every class member has an accessibility level that determines where the member will be visible. There are three of them available in C++: public, protected and private. The default access level for class members is private. To change the access level for a section of code, an access modifier is used followed by a colon. Every field or method that comes after this label will have the specified access level, until another access level is set or the class declaration ends.

class MyClass{  int myPrivate;   public:  int myPublic;  void publicMethod();};

Private access

All members regardless of their access level are accessible ...

Get C++ Quick Syntax Reference 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.