Search code examples
c++c++11nullptrtdm-gcc

nullptr not declared even with C++11 and C++14 enabled


I just installed CodeLite and the latest version of the TDM-GCC compiler. It supports both C++11 and C++14. However, when I write a program using nullptr it is still telling me that 'nullptr' was not declared in this scope .

enter image description here

What else do I have to do in order for nullptr to be accepted by the compiler?


Solution

  • You need to enable c++11 for your project. The dialog that you are showing allows you to modify the actual switches that are sent to the compiler for different options (I will explain this later).

    Firstly, to enable c++11 for your project, right-click on the project folder in the "Workspace View" (left pane) and select "Settings" (alternatively from the main menu bar Workspace->Open Active Project Settings... or Alt-F7).

    Select "Compiler" from the settings list (left side of the dialog) and then click on the ellipses to the right of the "C++ Compiler Options" option.

    This will present the "Compiler Options" dialog, here you can check "Enable C++11 features [-std=c++11]".

    Now, as I mentioned at the start, the dialog you are showing allows you to modify the switches sent to the compiler. Suppose you are using a compiler that has a switch "-std=gnu++11". You could add this switch in the "Build Settings" dialog (the one you show), and then check it in any of your projects that use this build tool.

    It is quite complicated, but needs to be to allow the use of different build tools that the IDE author hasn't even heard of.