Definition of names of an unknown (anonymous) C ++ namespace

C ++ 03 Standard 7.3.1.1 [namespace.unnamed] clause 1: (and the C ++ 11 standard also uses a similar definition)

A definition without namespace-name behaves as if it were replaced by

namespace unique { /* empty body */ } using namespace unique; namespace unique { namespace-body } 

Why is this not just a definition?

 namespace unique { namespace-body } using namespace unique; 

Side question: MSDN determines by the latest form. Does the Standard violate technically?

+7
source share
1 answer

You could no longer do this

 namespace { typedef int a; ::ax; } 

Note that in the following namespace { ... } , you might unexpectedly. That would be terribly inconsistent.

Also notice this case with two different valid results

 namespace A { void f(long); } using namespace A; namespace { void f(int); void g() { ::f(0); } } 

With ISO C ++, this invokes the int f version. With your alternative definition, it invokes the long version.

+7
source

All Articles