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

问题描述 投票:13回答:2

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

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

这是在其他地方可以使用的代码,相关部分是:

... = nullptr;

可能是什么问题?

这还不是关键字,不是全球范围吗?

c++ c++11 qt-creator nullptr
2个回答
33
投票

从QtCreator内部打开.pro文件并添加此

QMAKE_CXXFLAGS += -std=c++0x

0
投票

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

#ifndef _GXX_NULLPTR_T
#define _GXX_NULLPTR_T
   typedef decltype(nullptr) nullptr_t;
#endif 
/* C++11 */
© www.soinside.com 2019 - 2024. All rights reserved.