Member declarations can be labeled by an access-specifier:
access-specifier : member-specificationopt
An access-specifier specifies the access rules for members following it until the end of the class or until another access-specifier is encountered. [โExample:
class X { int a; // Xโ::โa is private by default: class used public: int b; // Xโ::โb is public int c; // Xโ::โc is public };
โโโend exampleโ]
Any number of access specifiers is allowed and no particular order is required. [โExample:
struct S { int a; // Sโ::โa is public by default: struct used protected: int b; // Sโ::โb is protected private: int c; // Sโ::โc is private public: int d; // Sโ::โd is public };
โโโend exampleโ]
[โNote: The effect of access control on the order of allocation of data members is described in [class.mem].โโโend noteโ]
When a member is redeclared within its class definition, the access specified at its redeclaration shall be the same as at its initial declaration. [โExample:
struct S { class A; enum E : int; private: class A { }; // error: cannot change access enum E: int { e0 }; // error: cannot change access };
โโโend exampleโ]
[โNote: In a derived class, the lookup of a base class name will find the injected-class-name instead of the name of the base class in the scope in which it was declared. The injected-class-name might be less accessible than the name of the base class in the scope in which it was declared. โโโend noteโ]
[โExample:
class A { }; class B : private A { }; class C : public B { A* p; // error: injected-class-name A is inaccessible ::A* q; // OK };
โโโend exampleโ]