tmp/tmppu1nzt1_/{from.md → to.md}
RENAMED
|
@@ -8,11 +8,11 @@ of the derived class. If a class is declared to be a base class for
|
|
| 8 |
another class using the `protected` access specifier, the public and
|
| 9 |
protected members of the base class are accessible as protected members
|
| 10 |
of the derived class. If a class is declared to be a base class for
|
| 11 |
another class using the `private` access specifier, the public and
|
| 12 |
protected members of the base class are accessible as private members of
|
| 13 |
-
the derived class.[^
|
| 14 |
|
| 15 |
In the absence of an *access-specifier* for a base class, `public` is
|
| 16 |
assumed when the derived class is defined with the *class-key* `struct`
|
| 17 |
and `private` is assumed when the class is defined with the *class-key*
|
| 18 |
`class`.
|
|
@@ -42,11 +42,13 @@ A member of a private base class can be inaccessible as inherited, but
|
|
| 42 |
accessible directly. Because of the rules on pointer conversions
|
| 43 |
[[conv.ptr]] and explicit casts
|
| 44 |
[[expr.type.conv]], [[expr.static.cast]], [[expr.cast]], a conversion
|
| 45 |
from a pointer to a derived class to a pointer to an inaccessible base
|
| 46 |
class can be ill-formed if an implicit conversion is used, but
|
| 47 |
-
well-formed if an explicit cast is used.
|
|
|
|
|
|
|
| 48 |
|
| 49 |
``` cpp
|
| 50 |
class B {
|
| 51 |
public:
|
| 52 |
int mi; // non-static member
|
|
@@ -69,10 +71,12 @@ void DD::f() {
|
|
| 69 |
::B* bp2 = (::B*)this; // OK with cast
|
| 70 |
bp2->mi = 3; // OK, access through a pointer to B.
|
| 71 |
}
|
| 72 |
```
|
| 73 |
|
|
|
|
|
|
|
| 74 |
— *end note*]
|
| 75 |
|
| 76 |
A base class `B` of `N` is *accessible* at *R*, if
|
| 77 |
|
| 78 |
- an invented public member of `B` would be a public member of `N`, or
|
|
@@ -82,11 +86,11 @@ A base class `B` of `N` is *accessible* at *R*, if
|
|
| 82 |
`N`, and an invented public member of `B` would be a private or
|
| 83 |
protected member of `P`, or
|
| 84 |
- there exists a class `S` such that `B` is a base class of `S`
|
| 85 |
accessible at *R* and `S` is a base class of `N` accessible at *R*.
|
| 86 |
|
| 87 |
-
[*Example
|
| 88 |
|
| 89 |
``` cpp
|
| 90 |
class B {
|
| 91 |
public:
|
| 92 |
int m;
|
|
@@ -113,33 +117,39 @@ derived class to a pointer to that base class
|
|
| 113 |
|
| 114 |
[*Note 2*: It follows that members and friends of a class `X` can
|
| 115 |
implicitly convert an `X*` to a pointer to a private or protected
|
| 116 |
immediate base class of `X`. — *end note*]
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
[*Note 3*: This class can be explicit, e.g., when a *qualified-id* is
|
| 123 |
used, or implicit, e.g., when a class member access operator
|
| 124 |
[[expr.ref]] is used (including cases where an implicit “`this->`” is
|
| 125 |
added). If both a class member access operator and a *qualified-id* are
|
| 126 |
-
used to name the member (as in `p->T::m`), the class
|
| 127 |
-
is the class
|
| 128 |
*qualified-id* (that is, `T`). — *end note*]
|
| 129 |
|
| 130 |
-
A member `m` is accessible at the point *R* when
|
|
|
|
| 131 |
|
|
|
|
| 132 |
- `m` as a member of `N` is public, or
|
| 133 |
- `m` as a member of `N` is private, and *R* occurs in a direct member
|
| 134 |
or friend of class `N`, or
|
| 135 |
- `m` as a member of `N` is protected, and *R* occurs in a direct member
|
| 136 |
or friend of class `N`, or in a member of a class `P` derived from
|
| 137 |
`N`, where `m` as a member of `P` is public, private, or protected, or
|
| 138 |
- there exists a base class `B` of `N` that is accessible at *R*, and
|
| 139 |
-
`m` is accessible at *R* when
|
| 140 |
-
\[*Example
|
| 141 |
``` cpp
|
| 142 |
class B;
|
| 143 |
class A {
|
| 144 |
private:
|
| 145 |
int i;
|
|
@@ -155,10 +165,10 @@ A member `m` is accessible at the point *R* when named in class `N` if
|
|
| 155 |
|
| 156 |
If a class member access operator, including an implicit “`this->`”, is
|
| 157 |
used to access a non-static data member or non-static member function,
|
| 158 |
the reference is ill-formed if the left operand (considered as a pointer
|
| 159 |
in the “`.`” operator case) cannot be implicitly converted to a pointer
|
| 160 |
-
to the
|
| 161 |
|
| 162 |
[*Note 4*: This requirement is in addition to the requirement that the
|
| 163 |
-
member be accessible as
|
| 164 |
|
|
|
|
| 8 |
another class using the `protected` access specifier, the public and
|
| 9 |
protected members of the base class are accessible as protected members
|
| 10 |
of the derived class. If a class is declared to be a base class for
|
| 11 |
another class using the `private` access specifier, the public and
|
| 12 |
protected members of the base class are accessible as private members of
|
| 13 |
+
the derived class.[^10]
|
| 14 |
|
| 15 |
In the absence of an *access-specifier* for a base class, `public` is
|
| 16 |
assumed when the derived class is defined with the *class-key* `struct`
|
| 17 |
and `private` is assumed when the class is defined with the *class-key*
|
| 18 |
`class`.
|
|
|
|
| 42 |
accessible directly. Because of the rules on pointer conversions
|
| 43 |
[[conv.ptr]] and explicit casts
|
| 44 |
[[expr.type.conv]], [[expr.static.cast]], [[expr.cast]], a conversion
|
| 45 |
from a pointer to a derived class to a pointer to an inaccessible base
|
| 46 |
class can be ill-formed if an implicit conversion is used, but
|
| 47 |
+
well-formed if an explicit cast is used.
|
| 48 |
+
|
| 49 |
+
[*Example 2*:
|
| 50 |
|
| 51 |
``` cpp
|
| 52 |
class B {
|
| 53 |
public:
|
| 54 |
int mi; // non-static member
|
|
|
|
| 71 |
::B* bp2 = (::B*)this; // OK with cast
|
| 72 |
bp2->mi = 3; // OK, access through a pointer to B.
|
| 73 |
}
|
| 74 |
```
|
| 75 |
|
| 76 |
+
— *end example*]
|
| 77 |
+
|
| 78 |
— *end note*]
|
| 79 |
|
| 80 |
A base class `B` of `N` is *accessible* at *R*, if
|
| 81 |
|
| 82 |
- an invented public member of `B` would be a public member of `N`, or
|
|
|
|
| 86 |
`N`, and an invented public member of `B` would be a private or
|
| 87 |
protected member of `P`, or
|
| 88 |
- there exists a class `S` such that `B` is a base class of `S`
|
| 89 |
accessible at *R* and `S` is a base class of `N` accessible at *R*.
|
| 90 |
|
| 91 |
+
[*Example 3*:
|
| 92 |
|
| 93 |
``` cpp
|
| 94 |
class B {
|
| 95 |
public:
|
| 96 |
int m;
|
|
|
|
| 117 |
|
| 118 |
[*Note 2*: It follows that members and friends of a class `X` can
|
| 119 |
implicitly convert an `X*` to a pointer to a private or protected
|
| 120 |
immediate base class of `X`. — *end note*]
|
| 121 |
|
| 122 |
+
An expression E that designates a member `m` has a *designating class*
|
| 123 |
+
that affects the access to `m`. This designating class is either
|
| 124 |
+
|
| 125 |
+
- the innermost class of which `m` is directly a member if E is a
|
| 126 |
+
*splice-expression* or
|
| 127 |
+
- the class in whose scope name lookup performed a search that found `m`
|
| 128 |
+
otherwise.
|
| 129 |
|
| 130 |
[*Note 3*: This class can be explicit, e.g., when a *qualified-id* is
|
| 131 |
used, or implicit, e.g., when a class member access operator
|
| 132 |
[[expr.ref]] is used (including cases where an implicit “`this->`” is
|
| 133 |
added). If both a class member access operator and a *qualified-id* are
|
| 134 |
+
used to name the member (as in `p->T::m`), the class designating the
|
| 135 |
+
member is the class designated by the *nested-name-specifier* of the
|
| 136 |
*qualified-id* (that is, `T`). — *end note*]
|
| 137 |
|
| 138 |
+
A member `m` is accessible at the point *R* when designated in class `N`
|
| 139 |
+
if
|
| 140 |
|
| 141 |
+
- `m` is designated by a *splice-expression*, or
|
| 142 |
- `m` as a member of `N` is public, or
|
| 143 |
- `m` as a member of `N` is private, and *R* occurs in a direct member
|
| 144 |
or friend of class `N`, or
|
| 145 |
- `m` as a member of `N` is protected, and *R* occurs in a direct member
|
| 146 |
or friend of class `N`, or in a member of a class `P` derived from
|
| 147 |
`N`, where `m` as a member of `P` is public, private, or protected, or
|
| 148 |
- there exists a base class `B` of `N` that is accessible at *R*, and
|
| 149 |
+
`m` is accessible at *R* when designated in class `B`.
|
| 150 |
+
\[*Example 4*:
|
| 151 |
``` cpp
|
| 152 |
class B;
|
| 153 |
class A {
|
| 154 |
private:
|
| 155 |
int i;
|
|
|
|
| 165 |
|
| 166 |
If a class member access operator, including an implicit “`this->`”, is
|
| 167 |
used to access a non-static data member or non-static member function,
|
| 168 |
the reference is ill-formed if the left operand (considered as a pointer
|
| 169 |
in the “`.`” operator case) cannot be implicitly converted to a pointer
|
| 170 |
+
to the designating class of the right operand.
|
| 171 |
|
| 172 |
[*Note 4*: This requirement is in addition to the requirement that the
|
| 173 |
+
member be accessible as designated. — *end note*]
|
| 174 |
|