在Linux上编译我的C++程序的过程中,出现如下警告:
warning #584: omission of exception specification is incompatible with previous function "__errno_location" (declared at line 43 of "/usr/include/bits/errno.h")
extern int errno;//error handling
^
代码如下:
#include <errno.h> //for error handling
#include <cmath>
#include <cstring>
#include <ctime>
extern int errno;//error handling
errno
是一个全局变量,在其他.cpp
文件中使用。我该如何解决这个问题?
最佳答案
errno
必须是“可修改的左值”,不一定是声明的对象。
显然在您的实现中,errno
扩展为一个表达式,其中包含对名为 __errno_location
的函数的调用.
在你自己的声明中:
extern int errno;
errno
扩展为该表达式,导致错误。
自 <errno.h>
已经声明errno
对您来说,没有必要自己声明,正如您所见,您不能自己声明。
只需省略 extern
声明。
关于c++ - 声明 `errno` 时出现编译时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19417623/