本文介绍了一个以上的重载函数实例与参数列表匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用时出现上述错误

double x = log10(100);

我在同一项目的其他班级中使用过它,并且不会显示此错误.

I have used it in other class, in the same project and it does not show this error.

我该如何解决?

非常感谢

钦丹

推荐答案

错误通常表明函数 log10 有多个重载,并且它们都不是更好的.例如,重载可能为 float double : 100 是一个 int ,可以转换为转换是等效的,因此编译器无法确定 best 选项是什么.

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

这篇关于一个以上的重载函数实例与参数列表匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 01:39