-1

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.

15
  • Possible duplicate of Can nullptr be emulated in gcc? Commented Mar 10, 2018 at 19:23
  • Did you add flag -std=c++0x inside Project Properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Miscellaneous? Commented Mar 10, 2018 at 19:23
  • 1
    Null pointer constant is available in GCC 4.6 and higher. gcc.gnu.org/projects/cxx-status.html Commented Mar 10, 2018 at 19:27
  • 1
    @SmitYcyken: Please do not answer in the comments section. Thank you. Commented Mar 10, 2018 at 19:32
  • 1
    @Klaus Explaining all the myriad reasons someone who programs in real life may be compiler-constrained is well out of the scope of a SO comment. You could ask a question on SoftwareEngineering.SE though. Commented Mar 10, 2018 at 20:10

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

Seems that nullptr is not supported with 4.4.7 but with GCC 4.6.0: http://gcc.gnu.org/gcc-4.6/changes.html You could try using NULL instead of nullptr

Comments

2

The specific nature of the error (the fact that it thinks it is an identifier that needs to be defined, rather than a keyword) makes it clear that your version of GCC simply doesn't support that C++11 feature.

There is no way to deal with this that doesn't involve changing compilers. You cannot effectively emulate this feature (because if you could, it wouldn't have needed to be a language feature in the first place). So if you cannot update your compiler, you cannot run code that expects all of C++11 to be implemented.

Comments

0

You can use Developer Toolset (DTS) to get a C++11 compiler which is compatible with the Red Hat Enterprise Linux 6 system libraries. The system compiler has very limited C++11 support only because it is too old—the first version of GCC 4.4 was released in 2009.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.