我不明白为什么这段代码无法编译:
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
转换为其自身的超类。在我的理解中,它不应该这样做。为什么会这样呢?