Summary: nullptr converts to bool, and bool converts to int, so why doesn\'t nullptr convert to int
Because it is exactly the main idea of nullptr.
nullptr was meant to avoid this behavior:
struct myclass {};
void f(myclass* a) { std::cout << "myclass\n"; }
void f(int a) { std::cout << "int\n"; }
// ...
f(NULL); // calls void f(int)
If nullptr were convertible to int this behavior would occur.
So the question is "why is it convertible to bool?".
Syntax-"suggarness":
int* a = nullptr;
if (a) {
}
Which looks way better than:
if (a == nullptr) {
}