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("Nan\n");
}
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 inclu

在C++11环境下,使用`isnan(x)`会导致编译错误,原因是libstdC++的一个bug。解决此问题的方法是通过明确指定作用域,如`::isnan(x)`或`std::isnan(x)`。该问题的更多细节及解决方案可参考GCC Bugzilla和Stack Overflow的相关讨论。
最低0.47元/天 解锁文章
3360

被折叠的 条评论
为什么被折叠?



