Namespaces
Variants
Views
Actions

std::nullptr_t

From cppreference.com
< cpp‎ | types
Revision as of 15:41, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
nullptr_t
(C++11)
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Primary type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++11)
(C++14)
Supported operations
Relationships and property queries
(C++11)
(C++11)
(C++11)
(C++11)
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
(C++11)
Type trait constants
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <cstddef>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
typedef decltype(nullptr) nullptr_t;
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

std::nullptr_t is the type of the null pointer literal, nullptr.

Example

If two or more overloads accept different pointer types, an overload for std::nullptr_t is necessary to accept a null pointer argument.

#include <cstddef>
#include <iostream>
 
void f(int* pi)
{
   std::cout << "Pointer to integer overload\n";
}
 
void f(double* pd)
{
   std::cout << "Pointer to double overload\n";
}
 
void f(std::nullptr_t nullp)
{
   std::cout << "null pointer overload\n";
}
 
int main()
{
    int* pi; double* pd;
 
    f(pi);
    f(pd);
    f(nullptr);  // would be ambiguous without void f(nullptr_t)
    // f(NULL);  // ambiguous overload: all three functions are candidates
}

Output:

Pointer to integer overload
Pointer to double overload
null pointer overload

See also

Template:cpp/language/dcl list nullptr
implementation-defined null pointer constant
(macro constant) [edit]