使用 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
Using Qt Creator C++ 11, nullptr is keyworded?
提问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 .pro
file 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 */