【发布时间】:2015-06-28 16:52:14
【问题描述】:
在这段代码中:
void f(float f, long int i) { cout << "1" << endl; }
void f(float f, float d) { cout << "2" << endl; }
int main() {
f(5.0f, 5);
}
有歧义。 Check it out!。但是,第二个参数是有符号整数。将int 绑定到long int 参数需要提升,但绑定到float 需要转换。
由于第一个参数是关于两个重载的完全匹配,它不计算在内。但是对于第二个参数,它在第一个超载(提升)的排名优于第二个(转换)的排名。
为什么会出现分辨率模糊,而不是选择第一个重载?
【问题讨论】:
标签: c++ type-conversion overloading type-promotion