C ++ - Why is nullptr_t not assigned int *?

cout << std::is_assignable<int*, std::nullptr_t>::value << endl;
cout << std::is_assignable<int*&, std::nullptr_t>::value << endl;

Output: 0 1

I do not understand why the first check returns false

I can assign a nullptr reference to a pointer, but I can not assign it to a raw pointer?

This is the opposite!

int* p = nullptr;
int*& pref = nullptr;

The second task, as expected, indicates an error:

error: cannot bind non-const lvalue reference of type int * & to rvalue of type int *

Can someone explain to me what is going on?

+4
source share
1 answer

cppreference .

std::is_assignable<int, int> false, std::is_assignable<int&, int> - true.

http://en.cppreference.com/w/cpp/types/is_assignable

+2

Source: https://habr.com/ru/post/1681741/


All Articles