C++03 Standard 7.3.1.1 [namespace.unnamed] paragraph 1: (and C++11 Standard also use similar definition)
An unnamed-namespace-definition behaves as if it were replaced by
namespace unique { /* empty body */ } using namespace unique; namespace unique { namespace-body }
Why not is it simply following definition?
namespace unique { namespace-body }
using namespace unique;
Side question: MSDN defines by latter form. Does it violate Standard technically?
You could not do this anymore
namespace { typedef int a; ::a x; }
Note that in a subsequent namespace { ... }
, suddenly you could. This would be horribly inconsistent.
Also notice this case, with two different valid outcomes
namespace A { void f(long); }
using namespace A;
namespace {
void f(int);
void g() {
::f(0);
}
}
With ISO C++, this calls the int
version of f
. With your alternative definition, it calls the long
version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With