【发布时间】:2011-07-19 03:20:04
【问题描述】:
以下 sn-p 在编译期间会产生“对 foo 的模糊调用”错误,我想知道是否有任何方法可以在不完全限定对 foo 的调用的情况下解决此问题:
#include <iostream>
struct Base1{
void foo(int){
}
};
struct Base2{
void foo(float){
}
};
struct Derived : public Base1, public Base2{
};
int main(){
Derived d;
d.foo(5);
std::cin.get();
return 0;
}
所以,问题正如标题所说。想法?我的意思是,以下工作完美无缺:
#include <iostream>
struct Base{
void foo(int){
}
};
struct Derived : public Base{
void foo(float){
}
};
int main(){
Derived d;
d.foo(5);
std::cin.get();
return 0;
}
【问题讨论】:
-
将两个foo(第二种情况)中的日志语句添加到调用哪个函数的常量中,你会感到惊讶……C++充满了神秘的规则;)
-
@Matthieu:喘气!该死的隐藏规则。 :(
标签: c++ scope overloading multiple-inheritance