November 15th, 2004, 3:31 pm
Athletico/DCFC,Many thanks for your answers.This is certainly not a trick question I made up. In fact, I had actually seen something like that in (bad ?) production code, though the nested declarations were redundant and not referenced outside.>>>>>>>I suspect Visual C++ treats your example syntactically as if the nested anon namespaces weren't there, so you'd access x2 and x3 exactly as you do x1. >>>>>>>>>>You seem to be right about that. Didn't occur to me earlier.>>>>>>>>>>Formally :: is known as the scope resolution operator, which to me implies an operand of a scope.>>>>>>>>>>>Yep, so ::x1 resolves from global namespace. No need to get into the name mangling scheme or the unique identifier.The following program ( which runs under Visual C++) should illustrate :#include <iostream>namespace { int x1=1;namespace{ int x2=2;namespace { int x3=3; }}}main(){ std::cout<<::x1; std::cout <<::x2; std::cout <<::x3;}