我不明白为什么这段代码不能编译:命名空间冲突在C++
namespace A {
class F {}; // line 2
class H : public F {};
}
namespace B {
void F(A::H x); // line 7
void G(A::H x) {
F(x); // line 9
}
}
我使用gcc 4.3.3
,错误是:
s3.cpp: In function ‘void B::G(A::H)’:
s3.cpp:2: error: ‘class A::F’ is not a function,
s3.cpp:7: error: conflict with ‘void B::F(A::H)’
s3.cpp:9: error: in call to ‘F’
我认为这是因为在第9行没有名称空间前缀,F(x)
应该明确表示只有B::F(x)
。编译器试图将x
转换成它自己的超类。根据我的理解,它不应该。它为什么这样做?
所谓的Koenig查找,实际上在3.4节中描述。2的C++标准。 – 2009-07-16 17:43:36
那么如果VS编译这个,这是一个错误? – liori 2009-07-16 17:45:18