What header file needs to be included for using nullptr in g++?

Arun picture Arun · Sep 21, 2010 · Viewed 40.7k times · Source

I am using g++ 4.4.1 and want to use nullptr, but I am not being able to find which header file is required to be included. It does not seem to be keyword either, because my attempt to use it is rejected as

error: 'nullptr' was not declared in this scope

Answer

ZoogieZork picture ZoogieZork · Sep 21, 2010

GCC 4.4.1 does not support nullptr.

Support for nullptr was added in GCC 4.6.0: http://gcc.gnu.org/gcc-4.6/changes.html

Improved experimental support for the upcoming C++0x ISO C++ standard, including support for nullptr (thanks to Magnus Fromreide), noexcept, unrestricted unions, range-based for loops (thanks to Rodrigo Rivas Costa), implicitly deleted functions and implicit move constructors.

For earlier versions of GCC, if you want to experiment with nullptr you can try the workaround in this SO question:

Can nullptr be emulated in GCC?