2.8 KiB
[class.access.spec]
11 Classes [class]
11.8 Member access control [class.access]
11.8.2 Access specifiers [class.access.spec]
Member declarations can be labeled by anaccess-specifier ([class.derived]):
access-specifier : member-specificationopt
Anaccess-specifier specifies the access rules for members following it until the end of the class or until anotheraccess-specifier is encountered.
[Example 1: class X {int a; // X::a is private by default: class usedpublic:int b; // X::b is publicint c; // X::c is public}; â end example]
Any number of access specifiers is allowed and no particular order is required.
[Example 2: struct S {int a; // S::a is public by default: struct usedprotected:int b; // S::b is protectedprivate:int c; // S::c is privatepublic:int d; // S::d is public}; â end example]
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 3: struct S {class A; enum E : int;private:class A { }; // error: cannot change accessenum E: int { e0 }; // error: cannot change access}; â end example]
[Note 1:
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 4: class A { };class B : private A { };class C : public B { A* p; // error: injected-class-name A is inaccessible::A* q; // OK}; â end example]