6 Basics [basic]

6.5 Name lookup [basic.lookup]

6.5.4 Qualified name lookup [basic.lookup.qual]

6.5.4.1 General [basic.lookup.qual.general]

The name of a class or namespace member or enumerator can be referred to after the ​::​ scope resolution operator ([expr.prim.id.qual]) applied to a nested-name-specifier that denotes its class, namespace, or enumeration.
If a ​::​ scope resolution operator in a nested-name-specifier is not preceded by a decltype-specifier, lookup of the name preceding that ​::​ considers only namespaces, types, and templates whose specializations are types.
If the name found does not designate a namespace or a class, enumeration, or dependent type, the program is ill-formed.
[Example 1: class A { public: static int n; }; int main() { int A; A::n = 42; // OK A b; // error: A does not name a type } — end example]
[Note 1:
Multiply qualified names, such as N1​::​N2​::​N3​::​n, can be used to refer to members of nested classes ([class.nest]) or members of nested namespaces.
— end note]
In a declaration in which the declarator-id is a qualified-id, names used before the qualified-id being declared are looked up in the defining namespace scope; names following the qualified-id are looked up in the scope of the member's class or namespace.
[Example 2: class X { }; class C { class X { }; static const int number = 50; static X arr[number]; }; X C::arr[number]; // error: // equivalent to ​::​X C​::​arr[C​::​number]; // and not to C​::​X C​::​arr[C​::​number]; — end example]
A name prefixed by the unary scope operator ​::​ ([expr.prim.id.qual]) is looked up in global scope, in the translation unit where it is used.
The name shall be declared in global namespace scope or shall be a name whose declaration is visible in global scope because of a using-directive ([namespace.qual]).
The use of ​::​ allows a global name to be referred to even if its identifier has been hidden.
A name prefixed by a nested-name-specifier that nominates an enumeration type shall represent an enumerator of that enumeration.
In a qualified-id of the form: the second type-name is looked up in the same scope as the first.
[Example 3: struct C { typedef int I; }; typedef int I1, I2; extern int* p; extern int* q; p->C::I::~I(); // I is looked up in the scope of C q->I1::~I2(); // I2 is looked up in the scope of the postfix-expression struct A { ~A(); }; typedef A AB; int main() { AB* p; p->AB::~AB(); // explicitly calls the destructor for A } — end example]
[Note 2:
[basic.lookup.classref] describes how name lookup proceeds after the . and -> operators.
— end note]