I am using Ubuntu.
When programming in C++, the nullptr
keyword is not recognized by the compiler.
It says it's not declared at this scope.
It doesn't work, even though I set the flag -std=c++11
.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI am using Ubuntu.
When programming in C++, the nullptr
keyword is not recognized by the compiler.
It says it's not declared at this scope.
It doesn't work, even though I set the flag -std=c++11
.
C++11 isn't a compiler, but an ISO standard implemented by a number of popular compilers. The default C++ compiler on Ubuntu is g++
from the GNU Compiler Collection. As you mentioned in your question, the -std=c++11
flag enables C++11 features in g++
as well as Clang, another C++ compiler available on Ubuntu.
The error message you see is shown when C++11 support is either not enabled or not supported by your compiler. GCC 4.6 was the first version to support nullptr
, so if you are using an earlier version, you will not be able to use nullptr
. Use g++ --version
to obtain the version installed.
Assuming you are using at least GCC 4.6, you will need to determine why your build system is not passing the correct flags to the compiler. In CMake, for example, you will need to use:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
g++ program.cpp -o run -std=c++11
Nov 3, 2014 at 0:19