'nullptr' was not declared in this scope

May 9, 2014 at 2:54pm
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
May 9, 2014 at 3:19pm
nullptr is a C++11 keyword. On GCC 4.8, you need to switch on C++11 support with -std=c++11
May 9, 2014 at 3:43pm
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
May 9, 2014 at 5:11pm
#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;
}
};
May 9, 2014 at 5:13pm
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 May 9, 2014 at 5:14pm
May 9, 2014 at 5:25pm
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'".
May 9, 2014 at 5:27pm
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 May 9, 2014 at 5:28pm
May 9, 2014 at 5:29pm
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 May 9, 2014 at 5:44pm
May 13, 2014 at 7:24pm
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.