RAD Studio
ContentsIndex
PreviousUpNext
using Directive

If you want to use several (or all of) the members of a namespace, C++ provides an easy way to get access to the complete namespace. The using-directive causes all identifiers in a namespace to be in scope at the point that the using-directive statement is made. The grammar for the using-directive is as follows. 

using-directive: 

using namespace :: opt nested-name-specifier opt namespace-name; 

The using-directive is transitive. When you apply the using directive to a namespace that contains using directives within itself, you get access to those namespaces as well. For example, if you apply the using directive in your program, you also get namespaces qux, foo, and bar.

   namespace qux {
      using namespace foo;  // This has been defined previously
      using namespace bar;  // This also has been defined previously
      }

The using-directive does not add any identifiers to your local scope. Therefore, an identifier defined in more than one namespace won't be a problem until you actually attempt to use it. Local scope declarations take precedence by hiding all other similar declarations.

Warning: Do not use the using
directive in header files. You might accidentally break namespaces in client code.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!