Home > Articles > Programming > C/C++

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Unnamed Namespaces

There is another namespace called the unnamed namespace. Each compilation unit has an unnamed namespace that differs from the other namespaces in one crucial way. Unnamed namespaces have no name! In other words, if I use the code in Listing 9, the symbol aFunction() will be placed in the unnamed namespace associated with the containing compilation unit.

Listing 9 Unnamed Namespace

namespace
{
   aFunction()
}

Symbols placed in the unnamed namespace cannot be used outside the scope of the compilation unit. This hides these symbols from other translation units unless the compilation unit with the namespace is #included.

  • + Share This
  • 🔖 Save To Your Account