Anonymous namespaces

From RAD Studio
Jump to: navigation, search

Go Up to C++ namespaces Index

The C++ grammar allows you to define anonymous namespaces. To do this, you use the keyword namespace with no identifier before the enclosing brace.

namespace {  // Anonymous namespace
  // Declarations
}

All anonymous, unnamed namespaces in global scope (that is, unnamed namespaces that are not nested) of the same translation unit share the same namespace. This way you can make static declarations without using the static keyword.

Each identifier that is enclosed within an unnamed namespace is unique within the translation unit in which the unnamed namespace is defined.