Description
A C++ namespace is used to group together a set of function, type, and data definitions. For example, in this code:
namespace A {
void f() {}
int x = 100;
}
there is a namespace A with two members f() and x.
Members of the namespace can be referenced by names like A::f()
or by saying using namespace A or using A::f.
A namespace represents a logical grouping of related declarations.
A namespace may be split into several parts, for example by saying:
namespace A {
void f() {}
}
...
namespace A {
void g() {}
}
which declares only one namespace, with two members f() and
g().
Concept
The sample program defines a namespace, and shows how members of the namespace are distinguished from global functions and data. To access namespace members, their names are prefaced with A::.
Special Notes:
The C++ Standard Library makes heavy use of namespaces, for example to define the std namespace that groups together standard functions and types. You frequently see:
using namespace std;at the top of programs, which means that members of the standard library are to be made available to the program.
Supported
Supported
Supported
