如何解决“fpclassify":对重载函数的不明确调用 [英] How to resolve "fpclassify': ambiguous call to overloaded function

查看:312
本文介绍了如何解决“fpclassify":对重载函数的不明确调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 C++ 和其他人一样陌生.我接到了安装模拟的任务,但我一直遇到错误代码.我能够解决其中的大部分问题,但有一个我不知道如何解决.

I am as new to C++ as someone can be. I have been given the task of installing a simulation but I keep running into error codes. I was able to resolve most of them but there is one I am not sure how to tackle.

错误代码为 C2668,其描述为fpclassify":对重载函数的模糊调用.项目为运行模拟",文件为第 415 行的 corecrt_math.h.

The error code is C2668 and its description is "fpclassify': ambiguous call to overloaded function. Project is "Run Simulation" and File is corecrt_math.h on line 415.

老实说,我不确定我提供的任何信息是否有任何用处,而且我不确定要提供哪些信息.也许你能问我一些问题,我能尽我所能回答他们会更好?我已经包含了我的 Visual Studio 19 的屏幕截图.

Honestly, I'm not sure if any of the information I have given is of any use, and I'm not sure what information to provide. Maybe it would be better if you could ask me some questions and I can answer them to the best of my ability? I have included a screenshot of my Visual Studio 19.


(点击图片放大)

可重现的示例(演示)

#include <cmath>

int main() {
    std::isnan(1);
}

预期结果:编译.

推荐答案

你可能以某种方式给 std::fpclassify 输入了一个整数.Visual Studio 的 <cmath> 函数的整数重载存在问题,该问题在您的情况下表现出来,而不是将整数转换为 double 符合:

You probably fed std::fpclassify an integer somehow. Visual Studio has an issue with the integer overloads for the <cmath> functions that manifests itself like in your case instead of casting the integer to a double in accordance with:

c.math.syn#2.2:

[…] 如果与 double 参数对应的算术类型的任何参数具有类型 double 或整数类型,则对应于 double 参数的算术类型被有效地强制转换为 double.

[…] if any argument of arithmetic type corresponding to a double parameter has type double or an integer type, then all arguments of arithmetic type corresponding to double parameters are effectively cast to double.

我写了一个错误报告对于 std::signbit 但对于我测试过的所有 函数和 std::fpclassify 都是一样的> 就是其中之一 - 它被许多其他 cmath 函数内部使用.

I wrote an error report for std::signbit but it's the same for all <cmath> functions that I've tested and std::fpclassify is one of them - and it's used internally by many other cmath functions.

corecrt_math.h 中的第 415 行位于 isnan 函数内,该函数在内部调用 fpclassify.

Line 415 in corecrt_math.h is within the isnan function which calls fpclassify internally.

解决问题的步骤:

  • 构建项目时,您会在错误列表框中看到错误列表.查找显示 的行,请参阅函数模板实例化 'bool isnan(_Ty) noexcept' 正在编译 或类似的参考. 部分可以是任何整数类型.
  • 双击该行,IDE 应将光标放在对 isnan 的调用上,该调用由一个整数组成.
  • isnan(static_cast(integer)).
  • 对导致问题的任何其他 cmath 函数重复这些步骤.
  • When you build your project you'll get a list of errors in the Error List box. Look for lines showing see reference to function template instantiation 'bool isnan<int>(_Ty) noexcept' being compiled or similar. The <int> part may be any integer type.
  • Double click that line and the IDE should place the cursor on the call to isnan that is made with an integer.
  • Replace the isnan(integer) call with isnan(static_cast<double>(integer)).
  • Repeat these steps for any other cmath functions causing problems.

注意:对整数使用 isnan 是没有意义的.isnan(integer) 将始终返回 false 所以编译器开启了优化应该用 false 替换整个调用.

Note: Using isnan with integers is pointless. isnan(integer) will always return false so a compiler with optimization turned on should replace the whole call with false.

这篇关于如何解决“fpclassify":对重载函数的不明确调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆