C++ 多个重载函数实例与参数列表匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13011361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
more than one instance of overloaded function matches the argument list
提问by chintan s
I am getting the above error when I use
使用时出现上述错误
double x = log10(100);
I have used it in other class, in the same project and it does not show this error.
我在同一个项目的其他班级中使用过它,但没有显示此错误。
How do I fix it?
我如何解决它?
Many thanks
非常感谢
Chintan
金丹
回答by David Rodríguez - dribeas
The error usually indicates that there is more than one overload for the function log10
and that none of them is betterthan the others for that particular call. For example, the overloads could take float
and double
: 100
is an int
that can be converted to either and the conversions are equivalent, so the compiler cannot determine what the bestoption is.
该错误通常表明该函数有多个重载,log10
并且对于该特定调用,没有一个比其他重载更好。例如,重载可以采用float
和double
:100
是int
可以转换为任何一个并且转换是等效的,因此编译器无法确定最佳选项是什么。
You can force the conversion to one of the overloads explicitly:
您可以明确强制转换为重载之一:
double x = log10( 100. ); // 100. is a double
float y = log10( 100f ); // 100f is a float
int i = 100;
double z = log10( static_cast<double>(i) ); // or cast