我是靠谱客的博主 难过舞蹈,最近开发中收集的这篇文章主要介绍编译错误: call of overloaded ‘isnan(double&)’ is ambiguous isnan(x);,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
C++11编译报错
测试
#include <stdlib.h>
#include <cmath>
#include <stdio.h>
using namespace std;
int main(int argc, char** argv)
{
double number = 0;
if (isnan(number))
{
printf("Nann");
}
return 0;
}
以上代码使用C++11编译时候会产生编译错误
test.cc: In function ‘int main()’:
test.cc:6:10: error: call of overloaded ‘isnan(double&)’ is ambiguous
isnan(x);
^
test.cc:6:10: note: candidates are:
In file included from /usr/include/features.h:374:0,
from /usr/include/x86_64-linux-gnu/c++/4.8/bits/os_defines.h:39,
from /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h:426,
from /usr/include/c++/4.8/cmath:41,
from test.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:234:1: note: int isnan(double)
__MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
^
In file included from test.cc:1:0:
/usr/include/c++/4.8/cmath:626:3: note: constexpr bool std::isnan(long double)
isnan(long double __x)
^
/usr/include/c++/4.8/cmath:622:3: note: constexpr bool std::isnan(double)
isnan(double __x)
^
/usr/include/c++/4.8/cmath:618:3: note: constexpr bool std::isnan(float)
isnan(float __x)
解决方式:
通过调用:: isnan或std :: isnan来明确限定isnan
原因:
这是libstdC++中的一个bug,详细原因可以看:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891
参考:
以上内容主要是Stack Overflow答案的翻译,原文链接:https://stackoverflow.com/questions/33770374/why-is-isnan-ambiguous-and-how-to-avoid-it
最后
以上就是难过舞蹈为你收集整理的编译错误: call of overloaded ‘isnan(double&)’ is ambiguous isnan(x);的全部内容,希望文章能够帮你解决编译错误: call of overloaded ‘isnan(double&)’ is ambiguous isnan(x);所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复