The using directive (C++ only)

A using directive provides access to all namespace qualifiers and the scope operator. This is accomplished by applying the using keyword to a namespace identifier.

Read syntax diagramSkip visual syntax diagramUsing directive syntax
 
>>-using--namespace--name--;-----------------------------------><
 

The name must be a previously defined namespace. The using directive may be applied at the global and local scope but not the class scope. Local scope takes precedence over global scope by hiding similar declarations.

If a scope contains a using directive that nominates a second namespace and that second namespace contains another using directive, the using directive from the second namespace will act as if it resides within the first scope.

namespace A {
  int i;
}
namespace B {
  int i;
  using namespace A;
}
void f()
{
  using namespace B;
  i = 7; // error
}

In this example, attempting to initialize i within function f() causes a compiler error, because function f() cannot know which i to call; i from namespace A, or i from namespace B.

Related information



[ Top of Page | Previous Page | Next Page | Contents | Index ]