以下代码:
class Base1
{
public:
void go() {}
};
class Base2
{
public:
void go(int a) {}
};
class Derived : public Base1, public Base2 {};
int main()
{
Derived d;
d.go(3);
return 0;
}
编译时会报错:
g++ -o a a.cc
a.cc: In function ‘int main()’:
a.cc:19:7: error: request for member ‘go’ is ambiguous
a.cc:10:10: error: candidates are: void Base2::go(int)
a.cc:4:10: error: void Base1::go()
make: *** [a] Error 1
很容易看出基类中的原型是不同的。但是为什么编译器不能检测到这一点并自动选择匹配的呢?