RAD Studio |  |

C++ namespaces
Collapse All

This section contains C++ name space topics.

Topics

Name | Description
Declaring A namespace | An original namespace declaration should use an identifier that has not been previously used as a global identifier.
Accessing Elements Of A namespace | There are three ways to access the elements of a namespace: by explicit access qualification, the using-declaration, or the using-directive. Remember that no matter which namespace you add to your local scope, identifiers in global scope (global scope is just another namespace) are still accessible by using the scope resolution operator ::. Explicit access qualification Using directive Using declaration Accessing namespaces in classes You cannot use a using directive inside a class. However, the using declarative is allowed and can be quite useful.
Anonymous namespaces | The C++ grammar allows you to define anonymous namespaces. To do this, you use the keyword namespace with no identifier before the enclosing brace.
Defining A namespace | The grammar for defining a namespace is
Explicit Access Qualification | You can explicitly qualify each member of a namespace. To do so, you use the namespace identifier together with the :: scope resolution operator followed by the member name. For example, to access a specific member of namespace ALPHA, you write:
Extending A namespace | Namespaces are discontinuous and open for additional development. If you redeclare a namespace, the effect is that you extend the original namespace by adding new declarations. Any extensions that are made to a namespace after a using-declaration, will not be known at the point at which the using-declaration occurs. Therefore, all overloaded versions of some function should be included in the namespace before you declare the function to be in use.
namespace Alias | You can use an alternate name to refer to a namespace identifier. An alias is useful when you need to refer to a long, unwieldy namespace identifier.
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... more

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