超负荷函数的一个以上实例匹配参数列表

more than one instance of overloaded function matches the argument list

本文关键字:参数 列表 实例 函数 一个以 超负荷      更新时间:2023-10-16

我使用

时会遇到上述错误
double x = log10(100);

我在其他类别中使用了它,在同一项目中没有显示此错误。

我该如何修复?

非常感谢

chintan

错误通常表明该函数log10有多个超负荷,并且对于该特定呼叫,它们都不是。例如,过载可以采用floatdouble100是一个可以转换为且转换等效的CC_4,因此编译器无法确定最佳选项是什么。选项。

您可以明确地将转换为一个过载:

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