more than one instance of overloaded function matches the argument list

 ̄綄美尐妖づ 提交于 2021-02-17 19:31:05

问题


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


回答1:


The error usually indicates that there is more than one overload for the function log10 and that none of them is better than 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 best option is.

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


来源:https://stackoverflow.com/questions/13011361/more-than-one-instance-of-overloaded-function-matches-the-argument-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!