Search code examples
c++gcccompiler-errorsg++nullptr

nullptr not declared when using -std=c++0x


Many other questions address similar issues, but I have yet to find an answer to this specific issue. I am getting the following error:

error: ‘nullptr’ was not declared in this scope

When compiling with the following command:

g++ -std=gnu++0x file1.cpp file2.cpp file3.cpp file4.cpp -o test.out

g++ version is 4.4.7, and unfortunately cannot be updated. Here is my system information:

LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: RedHatEnterpriseWorkstation
Description:    Red Hat Enterprise Linux Workstation release 6.9 (Santiago)
Release:    6.9
Codename:   Santiago

Note that my program compiles fine on MacOS High Sierra version 10.13 with the -std=c++11 flag, which is not available on the Linux machine. I would prefer not to polyfill nullptr if possible.


Edit

I repeat, adding the -std=c++0x flag DOES NOT WORK. It works on MacOS, but not the Linux machine. That is the problem, and why this is not the same as similar questions I have seen on SO.


Solution

  • Looking at the feature list of GCC it clearly shows :

    Null pointer constant | N2431 | GCC 4.6

    Which means that nullptr was implemented in GCC 4.6. GCC 4.4.7 doesn't support it yet, no flag is going to fix that. You're going to have to update your compiler if you want to use it.