cout << std::is_assignable<int*, std::nullptr_t>::value << endl;
cout << std::is_assignable<int*&, std::nullptr_t>::value << endl;
The output is: 0 1
I don't understand why the first check returns false
I can assign nullptr to a reference to pointer, but I cannot assign it to a raw pointer?
It's the inverse!
int* p = nullptr;
int*& pref = nullptr;
The second assignment, as expected, flags an error:
error: cannot bind non-const lvalue reference of type int*& to an rvalue of type int*
Can someone explain me what is going on?
The documentation on cppreference covers this.
std::is_assignable<int, int>
is false but std::is_assignable<int&, int>
is true.
http://en.cppreference.com/w/cpp/types/is_assignable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With