[英]How to resolve "fpclassify': ambiguous call to overloaded function
[英]"fpclassify': ambiguous call to overloaded function
我有一个与此非常相似的问题: 如何解决“fpclassify”:对重载 function 的模糊调用
我有一个包含大约 100 个 cpp 文件和 100 个头文件的大型项目,它们使用 GNU GCC 编译器在代码块中运行良好,但我想将该项目迁移到 VS19。 除了一个错误之外,它似乎工作正常: "fpclassify': ambiguous call to overloaded function
VS19 中的错误列表告诉我它位于corecrt_math.h
第 415 行的返回值上:
template <class _Ty>
_Check_return_ inline bool isnan(_In_ _Ty _X) throw()
{
return fpclassify(_X) == FP_NAN;
}
查看我的代码时,我发现我在 13 个文件、24 个位置(错误列表根本不涉及这些位置)中使用了std::isna
。 但是,与我上面链接的问题不同,我没有看到我检查int
是否在任何地方都是na
。 相反,我有这样的案例:
if (std::isnan(static_cast<double> (min)) && std::isnan(static_cast<double> (max)))
simulation_error("Error: No limits");
其中min
和max
定义为const double & min = NAN
和const double & max = NAN
( min
和max
在构造函数中设置)。
您对如何找到错误以及如何解决有任何想法吗? 我昨天尝试了很多小时 - 没有任何成功。
编辑:
完整的错误信息如下:
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(415,1): error C2668: 'fpclassify': ambiguous call to overloaded function
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(300,31): message : could be 'int fpclassify(long double) noexcept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(295,31): message : or 'int fpclassify(double) noexcept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(290,31): message : or 'int fpclassify(float) noexcept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(415,1): message : while trying to match the argument list '(_Ty)'
1> with
1> [
1> _Ty=bool
1> ]
1>C:\Users\Name\Documents\C++\Project name\Project name\src\module.cpp(668): message : see reference to function template instantiation 'bool isnan<bool>(_Ty) noexcept' being compiled
1> with
1> [
1> _Ty=bool
1> ]
其中指的是:
std::vector<double> stoprule_rel;,
if (!(std::isnan(static_cast<double> (stoprule_rel[i])
像fpclassify': ambiguous call to overloaded function
这样的错误信息总是伴随着notes 。 例如,对于一个简单的程序
#include <cmath>
int main() {
std::isnan(5);
}
VS抱怨:
corecrt_math.h(415): error C2668: 'fpclassify': ambiguous call to overloaded function
corecrt_math.h(300): note: could be 'int fpclassify(long double) throw()'
corecrt_math.h(295): note: or 'int fpclassify(double) throw()'
corecrt_math.h(290): note: or 'int fpclassify(float) throw()'
corecrt_math.h(415): note: while trying to match the argument list '(_Ty)'
with [ _Ty=int ]
<source>(3): note: see reference to function template instantiation 'bool isnan<int>(_Ty) throw()' being compiled
with [ _Ty=int ]
从这些注释中我们可以推断出_Ty
是int
并且在我们的源代码的第 3 行调用了std::nan
。 查看完整的编译器 output 进行编译,它会告诉您代码中触发错误的确切位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.