【发布时间】:2012-08-24 00:00:04
【问题描述】:
我不明白这里发生了什么
class A{};
class B : A {};
void func(A&, bool){}
void func(B&, double){}
int main(void)
{
B b;
A a;
bool bo;
double d;
func(b, bo);
}
编译时,Visual 2010 在func(b, bo); 行给我这个错误
2 overloads have similar conversions
could be 'void func(B &,double)'
or 'void func(A &,bool)'
while trying to match the argument list '(B, bool)'
我不明白为什么 bool 参数不足以解决过载问题。 我见过this question,正如在接受的答案中指出的那样,bool 应该更喜欢 bool 重载。就我而言,我看到第一个参数不足以选择好的功能,但是为什么第二个参数不能解决歧义呢?
【问题讨论】:
-
奇怪,尤其是因为隐式转换受到限制(私有继承)。
-
不是第一个参数不够选好的功能;就是第一个参数选择第二个函数,第二个参数选择第一个函数。所以没有一个被选中。
标签: c++ overloading