68 lines
4.2 KiB
Markdown
68 lines
4.2 KiB
Markdown
[namespace.qual]
|
||
|
||
# 6 Basics [[basic]](./#basic)
|
||
|
||
## 6.5 Name lookup [[basic.lookup]](basic.lookup#namespace.qual)
|
||
|
||
### 6.5.5 Qualified name lookup [[basic.lookup.qual]](basic.lookup.qual#namespace.qual)
|
||
|
||
#### 6.5.5.3 Namespace members [namespace.qual]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L2574)
|
||
|
||
Qualified name lookup in a namespace N additionally searches
|
||
every element of the inline namespace set of N ([[namespace.def]](namespace.def "9.9.2 Namespace definition"))[.](#1.sentence-1)
|
||
|
||
If nothing is found,
|
||
the results of the lookup are the results of qualified name lookup
|
||
in each namespace nominated by a [*using-directive*](namespace.udir#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") that precedes the point of the lookup and
|
||
inhabits N or an element of N's inline namespace set[.](#1.sentence-2)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
If a [*using-directive*](namespace.udir#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") refers to a namespace
|
||
that has already been considered, it does not affect the result[.](#1.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[*Example [1](#example-1)*: int x;namespace Y {void f(float); void h(int);}namespace Z {void h(double);}namespace A {using namespace Y; void f(int); void g(int); int i;}namespace B {using namespace Z; void f(char); int i;}namespace AB {using namespace A; using namespace B; void g();}void h(){ AB::g(); // g is declared directly in AB, therefore S is { AB::g() } and AB::g() is chosen AB::f(1); // f is not declared directly in AB so the rules are applied recursively to A and B;// namespace Y is not searched and Y::f(float) is not considered;// S is { A::f(int), B::f(char) } and overload resolution chooses A::f(int) AB::f('c'); // as above but resolution chooses B::f(char) AB::x++; // x is not declared directly in AB, and is not declared in A or B, so the rules// are applied recursively to Y and Z, S is { } so the program is ill-formed AB::i++; // i is not declared directly in AB so the rules are applied recursively to A and B,// S is { A::i, B::i } so the use is ambiguous and the program is ill-formed AB::h(16.8); // h is not declared directly in AB and not declared directly in A or B so the rules// are applied recursively to Y and Z, S is { Y::h(int), Z::h(double) } and// overload resolution chooses Z::h(double)} â *end example*]
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L2640)
|
||
|
||
[*Note [2](#note-2)*:
|
||
|
||
The same declaration found more than once is not an ambiguity (because
|
||
it is still a unique declaration)[.](#2.sentence-1)
|
||
|
||
[*Example [2](#example-2)*: namespace A {int a;}namespace B {using namespace A;}namespace C {using namespace A;}namespace BC {using namespace B; using namespace C;}void f(){ BC::a++; // OK, S is { A::a, A::a }}namespace D {using A::a;}namespace BD {using namespace B; using namespace D;}void g(){ BD::a++; // OK, S is { A::a, A::a }} â *end example*]
|
||
|
||
â *end note*]
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L2685)
|
||
|
||
[*Example [3](#example-3)*:
|
||
|
||
Because each referenced namespace is searched at most once, the
|
||
following is well-defined:namespace B {int b;}namespace A {using namespace B; int a;}namespace B {using namespace A;}void f(){ A::a++; // OK, a declared directly in A, S is { A::a } B::a++; // OK, both A and B searched (once), S is { A::a } A::b++; // OK, both A and B searched (once), S is { B::b } B::b++; // OK, b declared directly in B, S is { B::b }}
|
||
|
||
â *end example*]
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L2713)
|
||
|
||
[*Note [3](#note-3)*:
|
||
|
||
Class and enumeration declarations are not discarded
|
||
because of other declarations found in other searches[.](#4.sentence-1)
|
||
|
||
â *end note*]
|
||
|
||
[*Example [4](#example-4)*: namespace A {struct x { }; int x; int y;}namespace B {struct y { };}namespace C {using namespace A; using namespace B; int i = C::x; // OK, A::x (of type int)int j = C::y; // ambiguous, A::y or B::y} â *end example*]
|