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|
|
|
|
|
| 1 |
+
### General <a id="class.access.general">[[class.access.general]]</a>
|
| 2 |
+
|
| 3 |
+
A member of a class can be
|
| 4 |
+
|
| 5 |
+
- private, that is, it can be named only by members and friends of the
|
| 6 |
+
class in which it is declared;
|
| 7 |
+
- protected, that is, it can be named only by members and friends of the
|
| 8 |
+
class in which it is declared, by classes derived from that class, and
|
| 9 |
+
by their friends (see [[class.protected]]); or
|
| 10 |
+
- public, that is, it can be named anywhere without access restriction.
|
| 11 |
+
|
| 12 |
+
[*Note 1*: A constructor or destructor can be named by an expression
|
| 13 |
+
[[basic.def.odr]] even though it has no name. — *end note*]
|
| 14 |
+
|
| 15 |
+
A member of a class can also access all the members to which the class
|
| 16 |
+
has access. A local class of a member function may access the same
|
| 17 |
+
members that the member function itself may access.[^11]
|
| 18 |
+
|
| 19 |
+
Members of a class defined with the keyword `class` are `private` by
|
| 20 |
+
default. Members of a class defined with the keywords `struct` or
|
| 21 |
+
`union` are public by default.
|
| 22 |
+
|
| 23 |
+
[*Example 1*:
|
| 24 |
+
|
| 25 |
+
``` cpp
|
| 26 |
+
class X {
|
| 27 |
+
int a; // X::a is private by default
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
struct S {
|
| 31 |
+
int a; // S::a is public by default
|
| 32 |
+
};
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
— *end example*]
|
| 36 |
+
|
| 37 |
+
Access control is applied uniformly to declarations and expressions.
|
| 38 |
+
|
| 39 |
+
[*Note 2*: Access control applies to members nominated by friend
|
| 40 |
+
declarations [[class.friend]] and *using-declaration*s
|
| 41 |
+
[[namespace.udecl]]. — *end note*]
|
| 42 |
+
|
| 43 |
+
When a *using-declarator* is named, access control is applied to it, not
|
| 44 |
+
to the declarations that replace it. For an overload set, access control
|
| 45 |
+
is applied only to the function selected by overload resolution.
|
| 46 |
+
|
| 47 |
+
[*Example 2*:
|
| 48 |
+
|
| 49 |
+
``` cpp
|
| 50 |
+
struct S {
|
| 51 |
+
void f(int);
|
| 52 |
+
private:
|
| 53 |
+
void f(double);
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
void g(S* sp) {
|
| 57 |
+
sp->f(2); // OK, access control applied after overload resolution
|
| 58 |
+
}
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
— *end example*]
|
| 62 |
+
|
| 63 |
+
[*Note 3*:
|
| 64 |
+
|
| 65 |
+
Because access control applies to the declarations named, if access
|
| 66 |
+
control is applied to a *typedef-name*, only the accessibility of the
|
| 67 |
+
typedef or alias declaration itself is considered. The accessibility of
|
| 68 |
+
the entity referred to by the *typedef-name* is not considered. For
|
| 69 |
+
example,
|
| 70 |
+
|
| 71 |
+
``` cpp
|
| 72 |
+
class A {
|
| 73 |
+
class B { };
|
| 74 |
+
public:
|
| 75 |
+
typedef B BB;
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
void f() {
|
| 79 |
+
A::BB x; // OK, typedef A::BB is public
|
| 80 |
+
A::B y; // access error, A::B is private
|
| 81 |
+
}
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
— *end note*]
|
| 85 |
+
|
| 86 |
+
[*Note 4*: Access control does not prevent members from being found by
|
| 87 |
+
name lookup or implicit conversions to base classes from being
|
| 88 |
+
considered. — *end note*]
|
| 89 |
+
|
| 90 |
+
The interpretation of a given construct is established without regard to
|
| 91 |
+
access control. If the interpretation established makes use of
|
| 92 |
+
inaccessible members or base classes, the construct is ill-formed.
|
| 93 |
+
|
| 94 |
+
All access controls in [[class.access]] affect the ability to name a
|
| 95 |
+
class member from the declaration of a particular entity, including
|
| 96 |
+
parts of the declaration preceding the name of the entity being declared
|
| 97 |
+
and, if the entity is a class, the definitions of members of the class
|
| 98 |
+
appearing outside the class’s *member-specification*.
|
| 99 |
+
|
| 100 |
+
[*Note 5*: This access also applies to implicit references to
|
| 101 |
+
constructors, conversion functions, and destructors. — *end note*]
|
| 102 |
+
|
| 103 |
+
[*Example 3*:
|
| 104 |
+
|
| 105 |
+
``` cpp
|
| 106 |
+
class A {
|
| 107 |
+
typedef int I; // private member
|
| 108 |
+
I f();
|
| 109 |
+
friend I g(I);
|
| 110 |
+
static I x;
|
| 111 |
+
template<int> struct Q;
|
| 112 |
+
template<int> friend struct R;
|
| 113 |
+
protected:
|
| 114 |
+
struct B { };
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
A::I A::f() { return 0; }
|
| 118 |
+
A::I g(A::I p = A::x);
|
| 119 |
+
A::I g(A::I p) { return 0; }
|
| 120 |
+
A::I A::x = 0;
|
| 121 |
+
template<A::I> struct A::Q { };
|
| 122 |
+
template<A::I> struct R { };
|
| 123 |
+
|
| 124 |
+
struct D: A::B, A { };
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
Here, all the uses of `A::I` are well-formed because `A::f`, `A::x`, and
|
| 128 |
+
`A::Q` are members of class `A` and `g` and `R` are friends of class
|
| 129 |
+
`A`. This implies, for example, that access checking on the first use of
|
| 130 |
+
`A::I` must be deferred until it is determined that this use of `A::I`
|
| 131 |
+
is as the return type of a member of class `A`. Similarly, the use of
|
| 132 |
+
`A::B` as a *base-specifier* is well-formed because `D` is derived from
|
| 133 |
+
`A`, so checking of *base-specifier*s must be deferred until the entire
|
| 134 |
+
*base-specifier-list* has been seen.
|
| 135 |
+
|
| 136 |
+
— *end example*]
|
| 137 |
+
|
| 138 |
+
Access is checked for a default argument [[dcl.fct.default]] at the
|
| 139 |
+
point of declaration, rather than at any points of use of the default
|
| 140 |
+
argument. Access checking for default arguments in function templates
|
| 141 |
+
and in member functions of class templates is performed as described in
|
| 142 |
+
[[temp.inst]].
|
| 143 |
+
|
| 144 |
+
Access for a default *template-argument* [[temp.param]] is checked in
|
| 145 |
+
the context in which it appears rather than at any points of use of it.
|
| 146 |
+
|
| 147 |
+
[*Example 4*:
|
| 148 |
+
|
| 149 |
+
``` cpp
|
| 150 |
+
class B { };
|
| 151 |
+
template <class T> class C {
|
| 152 |
+
protected:
|
| 153 |
+
typedef T TT;
|
| 154 |
+
};
|
| 155 |
+
|
| 156 |
+
template <class U, class V = typename U::TT>
|
| 157 |
+
class D : public U { };
|
| 158 |
+
|
| 159 |
+
D <C<B> >* d; // access error, C::TT is protected
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
+
— *end example*]
|
| 163 |
+
|