Anonymous namespace

A recent thread on SO has caused this.

Anonymous namespace is considered equivalent

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

I do not remember the exact reason why it is not equivalent

  namespace unique { namespace-body } using namespace unique; 

Also tried to do a search (including Google), but in vain. Please share any information you have in this regard.

+4
source share
1 answer

A specification that currently exists was introduced in 1995 in N0783 to correct the angle. To quote this article (p. 9):

WP defines the semantics of an unnamed namespace as equivalent:

 namespace UNIQUE { // namespace body } using namespace UNIQUE; 

This is not true because the code in the unnamed namespace depends on whether the code is in the original namespace or the namespace extension.

 namespace {} // If you remove this line, the // use of ::f below is invalid namespace { void f() { using ::f; } } 

WP should be modified to define an unnamed namespace as equivalent:

 namespace UNIQUE {} using namespace UNIQUE; namespace UNIQUE { // namespace body } 
+4
source

All Articles