Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 
like image 293
Arun Avatar asked Sep 21 '10 00:09

Arun


People also ask

What library is nullptr in?

The C library Macro NULL is the value of a null pointer constant. It may be defined as ((void*)0), 0 or 0L depending on the compiler vendor.

What is the type of nullptr in C++?

std::nullptr_t is the type of the null pointer literal, nullptr. It is a distinct type that is not itself a pointer type or a pointer to member type. Its values are null pointer constants (see NULL), and may be implicitly converted to any pointer and pointer to member type.

What does nullptr point to?

The nullptr keyword represents a null pointer value. Use a null pointer value to indicate that an object handle, interior pointer, or native pointer type does not point to an object.

Is nullptr same as 0?

nullptr vs NULL NULL is 0(zero) i.e. integer constant zero with C-style typecast to void*, while nullptr is prvalue of type nullptr_t which is integer literal evaluates to zero.


1 Answers

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?

like image 79
ZoogieZork Avatar answered Sep 21 '22 14:09

ZoogieZork