Problems with using nullptr in g++

How do I check which C++ version my copy of g++ supports?
1
2
3
$ g++ --version
g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.


My reason for asking is that it barfs on the
nullptr line below

1
2
3
4
5
6
using namespace std;
...
int main(){
int* pn = nullptr;
...
}


saying nullptr is not declared in this scope.
But I thought nullptr was one of the new keywords?
So I'm assuming g++ is working to an older version
of C++. Or have I misunderstood something about nullptr?
Is it in a different namespace?
Last edited on
nullptr was added in C++11. To enable C++11 features you need to pass the compiler flag -std=c++11.
To compile the code as C++11, compile with the options -std=c++11 -pedantic-errors (both are required)
You may also want to use these additional options: -Wall -Wextra

Ideally, shun versions of the GNU implementation older than version 5.1.
Thanks folks, that works.
Topic archived. No new replies allowed.