[英]How to resolve "fpclassify': ambiguous call to overloaded function
我对 C++ 和其他人一样陌生。 我被赋予了安装模拟的任务,但我一直遇到错误代码。 我能够解决其中的大部分问题,但有一个我不知道如何解决。
错误代码为C2668
,其描述为:
“fpclassify”:对重载 function 的模糊调用
项目是“运行模拟”,文件是第 415 行的corecrt_math.h
。
老实说,我不确定我提供的任何信息是否有任何用处,我不确定要提供什么信息。 如果您能问我一些问题,我可以尽我所能回答,也许会更好?
我已经包含了我的 Visual Studio 19 的屏幕截图:
(点击图片放大)
可重现的示例(演示)
#include <cmath>
int main() {
std::isnan(1);
}
预期结果:它编译。
您可能以某种方式喂给了std::fpclassify
一个 integer 。 Visual Studio 对<cmath>
函数的 integer 重载存在问题,该函数在您的情况下表现出来,而不是根据以下情况将 integer 转换为double
精度:
[…] 如果对应于
double
参数的算术类型的任何参数的类型为double
或 integer 类型,则与double
参数对应的算术类型的所有 arguments 都会有效地转换为double
。
我为std::signbit
写了一个错误报告,但它对于我测试过的所有<cmath>
函数都是一样的, std::fpclassify
就是其中之一——它被许多其他cmath
函数在内部使用。
corecrt_math.h
中的第 415 行位于内部调用 fpclassify 的isnan
fpclassify
内。
解决问题的步骤:
see reference to function template instantiation 'bool isnan<int>(_Ty) noexcept' being compiled
或类似的行。 <int>
部分可以是任何 integer 类型。isnan
的调用上。isnan(static_cast<double>(
integer
))
替换isnan(
integer
)
调用。cmath
函数重复这些步骤。 注意:将isnan
与整数一起使用是没有意义的。 isnan(
integer
)
将始终返回false
因此启用优化的编译器应将整个调用替换为false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.