std::nullptr_t - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::nullptr_t

From cppreference.com
< cpp‎ | types

Defined in header `<cstddef>` |  |
typedef decltype(nullptr) nullptr_t; |  | (since C++11)

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

### [edit] Example

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

Run this code

    #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

### [edit] See also

nullptr | the pointer literal which specifies a null pointer value (C++11) [edit]
NULL | implementation-defined null pointer constant (macro constant) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/types/nullptr_t&oldid=63059"