Skip to Main Content
C++ In a Nutshell
book

C++ In a Nutshell

by Ray Lischner
May 2003
Intermediate to advanced content levelIntermediate to advanced
808 pages
32h 24m
English
O'Reilly Media, Inc.
Content preview from C++ In a Nutshell

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';
}

See Also

class, declaration, identifier, namespace, Chapter 2, Chapter 6

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ High Performance

C++ High Performance

Viktor Sehr, Björn Andrist
Optimized C++

Optimized C++

Kurt Guntheroth
Mastering C++ Programming

Mastering C++ Programming

Jeganathan Swaminathan

Publisher Resources

ISBN: 059600298XSupplemental ContentErrata Page