The using declaration and namespaces (C++ only)

A using declaration provides access to a specific namespace member. This is accomplished by applying the using keyword to a namespace name with its corresponding namespace member.

Read syntax diagramSkip visual syntax diagramUsing declaration syntax

In this syntax diagram, the qualifier name follows the using declaration and the member follows the qualifier name. For the declaration to work, the member must be declared inside the given namespace. For example:

namespace A {
  int i;
  int k;
  void f;
  void g;

using A::k

In this example, the using declaration is followed by A, the name of namespace A, which is then followed by the scope operator (::), and k. This format allows k to be accessed outside of namespace A through a using declaration. After issuing a using declaration, any extension made to that specific namespace will not be known at the point at which the using declaration occurs.

Overloaded versions of a given function must be included in the namespace prior to that given function's declaration. A using declaration may appear at namespace, block and class scope.

Related information