If I initialize a variable with a value of nullptr. and then I fetch a WinAPI function in to it that may return a value NULL on failure, do I have to use NULL or can I still check nullptr when checking what ever the function failed or not?
if ( windowfunctionresult == nullptr )
{
return false;
}
According to cppreference:
The keyword
nullptr
denotes the pointer literal. It is a prvalue of typestd::nullptr_t
. There exist implicit conversions fromnullptr
to null pointer value of any pointer type and any pointer to member type. Similar conversions exist for any null pointer constant, which includes values of typestd::nullptr_t
as well as the macroNULL
.
So nullptr
and NULL
will behave the same in the context of checking whether a pointer is null.
But you can also simply rely on the pointer-to-bool
conversion:
if ( !windowfunctionresult )
{
return false;
}