Name
using keyword — Looks up names in alternate classes or namespaces
Synopsis
block-decl := using-decl | using-directive using-decl ::= using [typename] [::] nested-name :: unqualified-id ; | using [::] unqualified-id ; using-directive ::= using namespace [::] [nested-name ::] namespace-name ;
The using
keyword starts a
using
declaration or using
directive.
A using
declaration
imports a name from another namespace into the current namespace. It
can also be used to introduce a name into a class scope; this is most
often used to promote the access level of an inherited member or bring
an inherited member into the derived class for overload
resolution.
A using
directive
tells the compiler to search an additional namespace when looking up
unqualified names.
Example
namespace math { const long double pi = 3.1415926535897932385L; };using
math::pi; long double tan(long double x = pi); int main( ) {using
namespace std; cout << "pi=" << math::pi << '\n'; }
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.