Show: Delphi C++
Display Preferences

Using Directive

From RAD Studio
Jump to: navigation, search

Go Up to C++ namespaces Index

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

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions