不允许将命名空间和同名的类放在一个声明区域中,即
namespace A {}
class A{};
格式不正确(见 §3.3.1/4)。但是,可以通过 using-directive 引入任一名称:
namespace N { namespace A {int i;} }
struct A {static int i;};
using namespace N;
int i = A::i; // The global struct, or namespace N::A?
main.cpp:7:9: error: reference to 'A' is ambiguous int i = A::i; ^ main.cpp:3:8: note: candidate found by name lookup is 'A' struct A {static int i;}; ^ main.cpp:1:25: note: candidate found by name lookup is 'N::A' namespace N { namespace A {int i;} } ^
但是,GCC 接受它。
谁是对的?