tmp/tmpjqtm0jzu/{from.md → to.md}
RENAMED
|
@@ -1,38 +1,38 @@
|
|
| 1 |
## Member name lookup <a id="class.member.lookup">[[class.member.lookup]]</a>
|
| 2 |
|
| 3 |
Member name lookup determines the meaning of a name (*id-expression*) in
|
| 4 |
-
a class scope
|
| 5 |
-
|
| 6 |
-
*
|
| 7 |
*qualified-id*, name lookup begins in the scope of the
|
| 8 |
*nested-name-specifier*. Name lookup takes place before access control (
|
| 9 |
-
[[basic.lookup]],
|
| 10 |
|
| 11 |
The following steps define the result of name lookup for a member name
|
| 12 |
`f` in a class scope `C`.
|
| 13 |
|
| 14 |
The *lookup set* for `f` in `C`, called S(f,C), consists of two
|
| 15 |
component sets: the *declaration set*, a set of members named `f`; and
|
| 16 |
the *subobject set*, a set of subobjects where declarations of these
|
| 17 |
members (possibly including *using-declaration*s) were found. In the
|
| 18 |
declaration set, *using-declaration*s are replaced by the set of
|
| 19 |
designated members that are not hidden or overridden by members of the
|
| 20 |
-
derived class
|
| 21 |
injected-class-names) are replaced by the types they designate. S(f,C)
|
| 22 |
is calculated as follows:
|
| 23 |
|
| 24 |
If `C` contains a declaration of the name `f`, the declaration set
|
| 25 |
contains every declaration of `f` declared in `C` that satisfies the
|
| 26 |
requirements of the language construct in which the lookup occurs.
|
| 27 |
|
| 28 |
-
[*Note 1*: Looking up a name in an *elaborated-type-specifier*
|
| 29 |
-
[[basic.lookup.elab]]
|
| 30 |
-
|
| 31 |
-
|
| 32 |
variable, and enumerator declarations. As another example, looking up a
|
| 33 |
-
name in a *using-declaration*
|
| 34 |
declaration of a class or enumeration that would ordinarily be hidden by
|
| 35 |
another declaration of that name in the same scope. — *end note*]
|
| 36 |
|
| 37 |
If the resulting declaration set is not empty, the subobject set
|
| 38 |
contains `C` itself, and calculation is complete.
|
|
@@ -83,11 +83,11 @@ S(x,F) is unambiguous because the `A` and `B` base class subobjects of
|
|
| 83 |
first merge step.
|
| 84 |
|
| 85 |
— *end example*]
|
| 86 |
|
| 87 |
If the name of an overloaded function is unambiguously found, overload
|
| 88 |
-
resolution
|
| 89 |
Ambiguities can often be resolved by qualifying a name with its class
|
| 90 |
name.
|
| 91 |
|
| 92 |
[*Example 2*:
|
| 93 |
|
|
@@ -134,11 +134,11 @@ struct D : B, C { };
|
|
| 134 |
|
| 135 |
void f(D* pd) {
|
| 136 |
pd->v++; // OK: only one v (virtual)
|
| 137 |
pd->s++; // OK: only one s (static)
|
| 138 |
int i = pd->e; // OK: only one e (enumerator)
|
| 139 |
-
pd->a++; // error
|
| 140 |
}
|
| 141 |
```
|
| 142 |
|
| 143 |
— *end example*]
|
| 144 |
|
|
@@ -161,17 +161,18 @@ struct B : virtual V, W {
|
|
| 161 |
struct C : virtual V, W { };
|
| 162 |
|
| 163 |
struct D : B, C { void glorp(); };
|
| 164 |
```
|
| 165 |
|
| 166 |
-
<a id="fig:
|
| 167 |
|
| 168 |
-
![Name lookup \[fig:
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
`W` are not hidden at
|
|
|
|
| 173 |
|
| 174 |
``` cpp
|
| 175 |
void D::glorp() {
|
| 176 |
x++; // OK: B::x hides V::x
|
| 177 |
f(); // OK: B::f() hides V::f()
|
|
@@ -197,20 +198,20 @@ struct C : A, virtual V { };
|
|
| 197 |
struct D : B, C { };
|
| 198 |
|
| 199 |
void g() {
|
| 200 |
D d;
|
| 201 |
B* pb = &d;
|
| 202 |
-
A* pa = &d; // error
|
| 203 |
V* pv = &d; // OK: only one V subobject
|
| 204 |
}
|
| 205 |
```
|
| 206 |
|
| 207 |
— *end example*]
|
| 208 |
|
| 209 |
[*Note 4*: Even if the result of name lookup is unambiguous, use of a
|
| 210 |
name found in multiple subobjects might still be ambiguous (
|
| 211 |
-
[[conv.mem]],
|
| 212 |
|
| 213 |
[*Example 6*:
|
| 214 |
|
| 215 |
``` cpp
|
| 216 |
struct B1 {
|
|
|
|
| 1 |
## Member name lookup <a id="class.member.lookup">[[class.member.lookup]]</a>
|
| 2 |
|
| 3 |
Member name lookup determines the meaning of a name (*id-expression*) in
|
| 4 |
+
a class scope [[basic.scope.class]]. Name lookup can result in an
|
| 5 |
+
ambiguity, in which case the program is ill-formed. For an
|
| 6 |
+
*unqualified-id*, name lookup begins in the class scope of `this`; for a
|
| 7 |
*qualified-id*, name lookup begins in the scope of the
|
| 8 |
*nested-name-specifier*. Name lookup takes place before access control (
|
| 9 |
+
[[basic.lookup]], [[class.access]]).
|
| 10 |
|
| 11 |
The following steps define the result of name lookup for a member name
|
| 12 |
`f` in a class scope `C`.
|
| 13 |
|
| 14 |
The *lookup set* for `f` in `C`, called S(f,C), consists of two
|
| 15 |
component sets: the *declaration set*, a set of members named `f`; and
|
| 16 |
the *subobject set*, a set of subobjects where declarations of these
|
| 17 |
members (possibly including *using-declaration*s) were found. In the
|
| 18 |
declaration set, *using-declaration*s are replaced by the set of
|
| 19 |
designated members that are not hidden or overridden by members of the
|
| 20 |
+
derived class [[namespace.udecl]], and type declarations (including
|
| 21 |
injected-class-names) are replaced by the types they designate. S(f,C)
|
| 22 |
is calculated as follows:
|
| 23 |
|
| 24 |
If `C` contains a declaration of the name `f`, the declaration set
|
| 25 |
contains every declaration of `f` declared in `C` that satisfies the
|
| 26 |
requirements of the language construct in which the lookup occurs.
|
| 27 |
|
| 28 |
+
[*Note 1*: Looking up a name in an *elaborated-type-specifier*
|
| 29 |
+
[[basic.lookup.elab]] or *base-specifier* [[class.derived]], for
|
| 30 |
+
instance, ignores all non-type declarations, while looking up a name in
|
| 31 |
+
a *nested-name-specifier* [[basic.lookup.qual]] ignores function,
|
| 32 |
variable, and enumerator declarations. As another example, looking up a
|
| 33 |
+
name in a *using-declaration* [[namespace.udecl]] includes the
|
| 34 |
declaration of a class or enumeration that would ordinarily be hidden by
|
| 35 |
another declaration of that name in the same scope. — *end note*]
|
| 36 |
|
| 37 |
If the resulting declaration set is not empty, the subobject set
|
| 38 |
contains `C` itself, and calculation is complete.
|
|
|
|
| 83 |
first merge step.
|
| 84 |
|
| 85 |
— *end example*]
|
| 86 |
|
| 87 |
If the name of an overloaded function is unambiguously found, overload
|
| 88 |
+
resolution [[over.match]] also takes place before access control.
|
| 89 |
Ambiguities can often be resolved by qualifying a name with its class
|
| 90 |
name.
|
| 91 |
|
| 92 |
[*Example 2*:
|
| 93 |
|
|
|
|
| 134 |
|
| 135 |
void f(D* pd) {
|
| 136 |
pd->v++; // OK: only one v (virtual)
|
| 137 |
pd->s++; // OK: only one s (static)
|
| 138 |
int i = pd->e; // OK: only one e (enumerator)
|
| 139 |
+
pd->a++; // error: ambiguous: two a{s} in D
|
| 140 |
}
|
| 141 |
```
|
| 142 |
|
| 143 |
— *end example*]
|
| 144 |
|
|
|
|
| 161 |
struct C : virtual V, W { };
|
| 162 |
|
| 163 |
struct D : B, C { void glorp(); };
|
| 164 |
```
|
| 165 |
|
| 166 |
+
<a id="fig:class.lookup"></a>
|
| 167 |
|
| 168 |
+
![Name lookup \[fig:class.lookup\]](images/figname.svg)
|
| 169 |
|
| 170 |
+
As illustrated in Figure [[fig:class.lookup]], the names declared in
|
| 171 |
+
`V` and the left-hand instance of `W` are hidden by those in `B`, but
|
| 172 |
+
the names declared in the right-hand instance of `W` are not hidden at
|
| 173 |
+
all.
|
| 174 |
|
| 175 |
``` cpp
|
| 176 |
void D::glorp() {
|
| 177 |
x++; // OK: B::x hides V::x
|
| 178 |
f(); // OK: B::f() hides V::f()
|
|
|
|
| 198 |
struct D : B, C { };
|
| 199 |
|
| 200 |
void g() {
|
| 201 |
D d;
|
| 202 |
B* pb = &d;
|
| 203 |
+
A* pa = &d; // error: ambiguous: C's A or B's A?
|
| 204 |
V* pv = &d; // OK: only one V subobject
|
| 205 |
}
|
| 206 |
```
|
| 207 |
|
| 208 |
— *end example*]
|
| 209 |
|
| 210 |
[*Note 4*: Even if the result of name lookup is unambiguous, use of a
|
| 211 |
name found in multiple subobjects might still be ambiguous (
|
| 212 |
+
[[conv.mem]], [[expr.ref]], [[class.access.base]]). — *end note*]
|
| 213 |
|
| 214 |
[*Example 6*:
|
| 215 |
|
| 216 |
``` cpp
|
| 217 |
struct B1 {
|