Unnamed namespaces

An unnamed-namespace-definition behaves as if it were replaced by:

namespace unique { namespace-body }
using namespace unique;

Each unnamed namespace has an identifier, represented by unique, that differs from all other identifiers in the entire program. For example:

namespace { int i; }          // unique::i
void f() { i++; }             // unique::i++

namespace A {
    namespace {
        int I;      // A::unique::i
        int j;      // A::unique::j
    }
}

using namespace A;

void h()
{
    I++;            //error: unique::i or A::unique::i
    A::i++;         // error: A::i undefined
    j++;            // A::unique::j++
}

Unnamed namespaces are a superior replacement for the static declaration of variables. They allow variables and functions to be visible within an entire translation unit, yet not visible externally. Although entities in an unnamed namespace might have external linkage, they are effectively qualified by a name unique to their translation unit and therefore can never be seen from any other translation unit.