Description
A namespace that you declare need not have a name. For example, if you say:
namespace { void f() {} }then this is equivalent to saying:
namespace InternalGeneratedName { void f() {} } using namespace InternalGeneratedName;
Such namespaces can be used to protect against name clashes with names declared outside of the current compilation unit. If we instead used a name N for the namespace, there is a possibility that N is already in use elsewhere, whereas with unnamed namespaces, there is a guarantee that the internally generated name will be unique and will not clash with unnamed namespaces in other compilation units.
Using unnamed namespaces is preferable to the use of static to mean "use internal linkage". static is a confusing keyword, used in a variety of ways in C++, and unnamed namespaces offer an alternative.
Concept
The example program defines an unnamed namespace and then accesses its members. The members are implicitly made available via an internal using namespace directive. Declaring x in this way is preferable to using a static declaration, such as is done for y in the sample program.
Supported
Supported
Supported