[namespace.qual] (original) (raw)

6 Basics [basic]

6.5 Name lookup [basic.lookup]

6.5.5 Qualified name lookup [basic.lookup.qual]

6.5.5.3 Namespace members [namespace.qual]

Qualified name lookup in a namespace N additionally searches every element of the inline namespace set of N ([namespace.def]).

If nothing is found, the results of the lookup are the results of qualified name lookup in each namespace nominated by a using-directivethat precedes the point of the lookup and inhabits N or an element of N's inline namespace set.

[Note 1:

If a using-directive refers to a namespace that has already been considered, it does not affect the result.

— _end note_]

[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(); AB::f(1); AB::f('c'); AB::x++; AB::i++; AB::h(16.8); } — _end example_]

[Note 2:

The same declaration found more than once is not an ambiguity (because it is still a unique declaration).

[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++; } namespace D { using A::a;} namespace BD { using namespace B;using namespace D;} void g() { BD::a++; } — _end example_]

— _end note_]

[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++; B::a++; A::b++; B::b++; }

— _end example_]

[Note 3:

Class and enumeration declarations are not discarded because of other declarations found in other searches.

— _end note_]

[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; int j = C::y; } — _end example_]