GCC 7.5 中的“'nullptr' 未在此范围内声明”

"'nullptr' was not declared in this scope" in GCC 7.5

我正在使用 GCC 7.5。构建包时,它抱怨整数和指针之间的有序比较,所以我将比较中的 0 更改为 nullptr。

但随后我收到一条错误消息,指出“'nullptr' 未在此范围内声明”。

尝试添加选项 -std=c++11 或 -std=c++14 没有帮助。

所有程序均使用 C++。

it complains about ordered comparison between integer and pointer

“有序比较”是指与><>=<=进行比较。以这种方式比较指针和空指针常量是没有意义的。

so I change the 0 in the comparison to nullptr

这不会使比较更有意义。以这种方式比较指针和空指针常量也是没有意义的。

But then I receive an error message that "'nullptr' was not declared in this scope".

gcc 7.5 不会发生这种情况,除非你

  • 编译 C 而不是 C++ 或者
  • 在某处传递-std=c++98-std=c++03
  • gcc 安装有问题。

在任何情况下,您可能想要修复比较(也许将 >< 更改为 !=),然后才考虑将 0 替换为 nullptr.