'nullptr' was not declared in this scope

I am using JGrasp as IDE. I have confirmed by "Actual command sent" that the compiler being used is TDM-GCC-64\bin\g++.exe, and I have confirmed that the edition of g++ is 4.8.1, which should recognize the 'nullptr' keyword along with most of C++11. I have '-std=c++11' in the args for the compiler and linker. Having confirmed all of this multiple times, I cannot understand what is causing the error:
'nullptr' was not declared in this scope
nullptr is a C++11 keyword. On GCC 4.8, you need to switch on C++11 support with -std=c++11
kbw wrote:
On GCC 4.8, you need to switch on C++11 support with -std=c++11
ath2441 wrote:
I have '-std=c++11' in the args for the compiler and linker


could you post your source code? maybe you are making an error somewhere else, which is resulting in it not recognizing nullptr
#include <iostream>
using namespace std;
class Person
{
private:
string name;
public:
Person(){}
Person(string theName)
{
name = theName;
}
Person(Person& other)
{
if (other != nullptr)
name = other.name;
}
};
You could always just do if(other) though person other isn't a pointer anyways so not sure exactly what you are trying to do.
Last edited on
The variable other is a reference and my understanding is that references are pointers internally.

Using if(other) produces the error: "could not convert 'other' from 'Person' to 'bool'".
Yeah I typed that then realized it wasn't a pointer. You could always just pass as a pointer and do it the way you are now. Or maybe change the if statement to something like if(!other.name.empty())
Last edited on
Now that I think of this, I understand why my code was incorrect. The variable other is a reference to an object and probing whether it is null is unnecessary because null references are illegal. The compiler error was very misleading.
Last edited on
I learned why the compiler error was so misleading. '-std=c++11' was in ARGS2 of the JGrasp compiler settings when it should have been in ARGS1.
Topic archived. No new replies allowed.