Anonymous namespaces

From RAD Studio
Revision as of 06:42, 11 September 2015 by AChaves (talk | contribs) (RS-68398)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.