tmp/tmp4tv0vuxq/{from.md → to.md}
RENAMED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
-
## Protected member access <a id="class.protected">[[class.protected]]</a>
|
| 2 |
|
| 3 |
-
An additional access check beyond those described earlier in
|
| 4 |
[[class.access]] is applied when a non-static data member or non-static
|
| 5 |
-
member function is a protected member of its naming class
|
| 6 |
-
[[class.access.base]]
|
| 7 |
member is granted because the reference occurs in a friend or member of
|
| 8 |
-
some class `C`. If the access is to form a pointer to member
|
| 9 |
-
[[expr.unary.op]]
|
| 10 |
class derived from `C`. All other accesses involve a (possibly implicit)
|
| 11 |
-
object expression
|
| 12 |
expression shall be `C` or a class derived from `C`.
|
| 13 |
|
| 14 |
[*Example 1*:
|
| 15 |
|
| 16 |
``` cpp
|
|
@@ -27,35 +27,35 @@ class D2 : public B {
|
|
| 27 |
friend void fr(B*,D1*,D2*);
|
| 28 |
void mem(B*,D1*);
|
| 29 |
};
|
| 30 |
|
| 31 |
void fr(B* pb, D1* p1, D2* p2) {
|
| 32 |
-
pb->i = 1; //
|
| 33 |
-
p1->i = 2; //
|
| 34 |
p2->i = 3; // OK (access through a D2)
|
| 35 |
p2->B::i = 4; // OK (access through a D2, even though naming class is B)
|
| 36 |
-
int B::* pmi_B = &B::i; //
|
| 37 |
int B::* pmi_B2 = &D2::i; // OK (type of &D2::i is int B::*)
|
| 38 |
-
B::j = 5; //
|
| 39 |
D2::j = 6; // OK (because refers to static member)
|
| 40 |
}
|
| 41 |
|
| 42 |
void D2::mem(B* pb, D1* p1) {
|
| 43 |
-
pb->i = 1; //
|
| 44 |
-
p1->i = 2; //
|
| 45 |
i = 3; // OK (access through this)
|
| 46 |
B::i = 4; // OK (access through this, qualification ignored)
|
| 47 |
-
int B::* pmi_B = &B::i; //
|
| 48 |
int B::* pmi_B2 = &D2::i; // OK
|
| 49 |
j = 5; // OK (because j refers to static member)
|
| 50 |
B::j = 6; // OK (because B::j refers to static member)
|
| 51 |
}
|
| 52 |
|
| 53 |
void g(B* pb, D1* p1, D2* p2) {
|
| 54 |
-
pb->i = 1; //
|
| 55 |
-
p1->i = 2; //
|
| 56 |
-
p2->i = 3; //
|
| 57 |
}
|
| 58 |
```
|
| 59 |
|
| 60 |
— *end example*]
|
| 61 |
|
|
|
|
| 1 |
+
### Protected member access <a id="class.protected">[[class.protected]]</a>
|
| 2 |
|
| 3 |
+
An additional access check beyond those described earlier in
|
| 4 |
[[class.access]] is applied when a non-static data member or non-static
|
| 5 |
+
member function is a protected member of its naming class
|
| 6 |
+
[[class.access.base]].[^13] As described earlier, access to a protected
|
| 7 |
member is granted because the reference occurs in a friend or member of
|
| 8 |
+
some class `C`. If the access is to form a pointer to member
|
| 9 |
+
[[expr.unary.op]], the *nested-name-specifier* shall denote `C` or a
|
| 10 |
class derived from `C`. All other accesses involve a (possibly implicit)
|
| 11 |
+
object expression [[expr.ref]]. In this case, the class of the object
|
| 12 |
expression shall be `C` or a class derived from `C`.
|
| 13 |
|
| 14 |
[*Example 1*:
|
| 15 |
|
| 16 |
``` cpp
|
|
|
|
| 27 |
friend void fr(B*,D1*,D2*);
|
| 28 |
void mem(B*,D1*);
|
| 29 |
};
|
| 30 |
|
| 31 |
void fr(B* pb, D1* p1, D2* p2) {
|
| 32 |
+
pb->i = 1; // error
|
| 33 |
+
p1->i = 2; // error
|
| 34 |
p2->i = 3; // OK (access through a D2)
|
| 35 |
p2->B::i = 4; // OK (access through a D2, even though naming class is B)
|
| 36 |
+
int B::* pmi_B = &B::i; // error
|
| 37 |
int B::* pmi_B2 = &D2::i; // OK (type of &D2::i is int B::*)
|
| 38 |
+
B::j = 5; // error: not a friend of naming class B
|
| 39 |
D2::j = 6; // OK (because refers to static member)
|
| 40 |
}
|
| 41 |
|
| 42 |
void D2::mem(B* pb, D1* p1) {
|
| 43 |
+
pb->i = 1; // error
|
| 44 |
+
p1->i = 2; // error
|
| 45 |
i = 3; // OK (access through this)
|
| 46 |
B::i = 4; // OK (access through this, qualification ignored)
|
| 47 |
+
int B::* pmi_B = &B::i; // error
|
| 48 |
int B::* pmi_B2 = &D2::i; // OK
|
| 49 |
j = 5; // OK (because j refers to static member)
|
| 50 |
B::j = 6; // OK (because B::j refers to static member)
|
| 51 |
}
|
| 52 |
|
| 53 |
void g(B* pb, D1* p1, D2* p2) {
|
| 54 |
+
pb->i = 1; // error
|
| 55 |
+
p1->i = 2; // error
|
| 56 |
+
p2->i = 3; // error
|
| 57 |
}
|
| 58 |
```
|
| 59 |
|
| 60 |
— *end example*]
|
| 61 |
|