使用 Qt Creator C++ 11,nullptr 是关键字?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16509932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:25:42  来源:igfitidea点击:

Using Qt Creator C++ 11, nullptr is keyworded?

c++c++11qt-creatornullptr

提问by alan2here

I'm using C++11 using Qt Creator.

我正在通过 Qt Creator 使用 C++11。

"warning: identifier 'nullptr' is a keyword in C++11 [-Wc++0x-compat]"
"error: 'nullptr' was not declared in this scope"

This is on code that works elsewhere, the relevant part being:

这是在其他地方工作的代码,相关部分是:

... = nullptr;

What might be the problem?

可能是什么问题?

Is this not already a keyword, isn't it's scope global?

这不是已经是关键字了吗,它的作用域不是全局的吗?

回答by user2348816

Open your .profile from inside QtCreator and add this

.pro从 QtCreator 内部打开您的文件并添加这个

QMAKE_CXXFLAGS += -std=c++0x

回答by Dark Oldman

Try adding the below lines to your cpp source code

尝试将以下几行添加到您的 cpp 源代码中

#ifndef _GXX_NULLPTR_T
#define _GXX_NULLPTR_T
   typedef decltype(nullptr) nullptr_t;
#endif 
/* C++11 */