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.

  • It would be helpful if you could state what compiler you are using. Nov 2, 2014 at 23:06
  • I am using the compiler g++ Nov 2, 2014 at 23:37

1 Answer 1


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")
  • Thanks. How to fix it then? I am using Ubuntu 14 Nov 2, 2014 at 23:26
  • How are you compiling the program? Nov 2, 2014 at 23:27
  • g++ -o -std=c++11 run program.cpp Nov 2, 2014 at 23:38
  • 1
    The order of arguments is wrong. It should be g++ program.cpp -o run -std=c++11 Nov 3, 2014 at 0:19
  • Yes, it's the order of command. Nov 6, 2014 at 4:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.