Export (0) Print
Expand All

Explicit Qualification

Namespace members can be accessed using an explicit qualifier and the scope-resolution operator.

For example:

// explicit_qualification.cpp
int i;

namespace A
{
   int a, b, c;

   namespace B
   {
      int i, j, k;
   }
}

int main()
{
   A::a++;
   A::B::i++;   // B's i
   ::i++;   // the global I
}

The statement ::i++ accesses the i that is declared in the first statement of the example. Such usage of the scope-resolution operator without a preceding qualifier invokes the global namespace.

Usage of explicit qualification might be cumbersome with longer names or in large programs. The using declaration, using directive, and namespace aliases provide more straightforward ways to reference namespace members.

For more information, see Qualified Names.

Community Additions

ADD
Show:
© 2014 Microsoft