Why does not std::nullptr_t work with std::cout in C++?

Viewed 1183

I learned about std::nullptr_t that is the type of the null pointer literal, nullptr.

Then I made small program :

#include <iostream>

int main() 
{
    std::nullptr_t n1; 
    std::cout<<n1<<endl;
    return 0;
} 

Here, nullptr_t is data type and n1 is variable and I'm trying to print the value of variable. But, Compiler give an error:

prog.cpp: In function 'int main()':
prog.cpp:6:11: error: ambiguous overload for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'std::nullptr_t')
  std::cout<<n1<<endl;

Why does not std::nullptr_t work with std::cout in C++? What am I wrong here?

1 Answers
Related