RAD Studio |  |

using Directive
See Also
Collapse All

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.

Copy Code

       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.
See Also

Accessing Elements Of A namespace

using (declaration)

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!