cpp/language/using declaration

Introduces a name that is defined elsewhere into the declarative region where this using-declaration appears.

Explanation
Using-declarations can be used to introduce namespace members into other namespaces and block scopes, or to introduce base class members into derived class definitions.

In namespace and block scope
Using-declaration introduces a member of another namespace into current namespace or block scope.

See for details.

In class definition
Using-declaration introduces a member of a base class into the derived class definition, such as to expose a protected member of base as public member of derived. In this case, must name a base class of the one being defined. If the name is the name of an overloaded member function of the base class, all base class member functions with that name are introduced. If the derived class already has a member with the same name, parameter list, and qualifications, the derived class member hides or overrides (doesn't conflict with) the member that is introduced from the base class.

{{rrev|since=c++11|1=

Inheriting constructors
If the using-declaration refers to a constructor of a direct base of the class being defined (e.g. ), all constructors of that base (ignoring member access) are made visible to overload resolution when initializing the derived class.

If overload resolution selects an inherited constructor, it is accessible if it would be accessible when used to construct an object of the corresponding base class: the accessibility of the using-declaration that introduced it is ignored.

If overload resolution selects one of the inherited constructors when initializing an object of such derived class, then the subobject from which the constructor was inherited is initialized using the inherited constructor, and all other bases and members of  are initialized as if by the defaulted default constructor (default member initializers are used if provided, otherwise default initialization takes place). The entire initialization is treated as a single function call: initialization of the parameters of the inherited constructor is sequenced-before initialization of any base or member of the derived object.

If the constructor was inherited from multiple base class subobjects of type B, the program is ill-formed, similar to multiply-inherited non-static member functions:

As with using-declarations for any other non-static member functions, if an inherited constructor matches the signature of one of the constructors of, it is hidden from lookup by the version found in. If one of the inherited constructors of happens to have the signature that matches a copy/move constructor of the, it does not prevent implicit generation of  copy/move constructor (which then hides the inherited version, similar to ).

Within a, if a using-declaration refers to a , it is considered to name a constructor if the has a terminal name that is the same as the.

}}

{{rrev|since=c++20|

Introducing scoped enumerators
In addition to members of another namespace and members of base classes, using-declaration can also introduce enumerators of into namespace, block, and class scopes.

A using-declaration can also be used with unscoped enumerators.

}}