TITLE: anonymous namespaces PROBLEM: jazzbeau@netcom.com (Steve Barnette) Given the following code: static int i; namespace { int j; } int main() { ::i = 0; ::j = 0; // error? return 0; } Should ::j allow access to the integer defined in the anonymous namespace as does the classic static definition? RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 27 Oct 95 An unnamed namespace definition acts as if it were followed by a using-directive for that (unnameable) namespace. The names declared in that namespace are thus brought into the enclosing scope. In your example, 'j' is brought into global scope. (Reference: WP section 7.3.1.1, 7.3.4) The unary '::' restricts name lookup to those names declared at global scope, or visible in global scope due to a using-declaration. (WP 3.4.2) Your example of "::j" therefore is valid and refers to the "j" in the unnamed namespace. Unnamed namespaces at global scope act much like "static" declarations, but are more flexible. You can nest unnamed namespaces in other namespaces, for example. The use of 'static' inside a namespace is deprecated.