#Object Usage
Object Usage
#Object Usage
Object Usage
Some also prefer to reverse those (giving "Yoda conditions"):
if (nullptr == renderer)
This way, if you accidentally use =
where you meant ==
:
if (nullptr = renderer)
...the code won't compile, because you've attempted to assign to a constant (whereas if (renderer = nullptr)
could compile and do the wrong thing, though most current compilers will at least give a warning about it).
Some also prefer to reverse those (giving "Yoda conditions"):
if (nullptr == renderer)
This way, if you accidentally use =
where you meant ==
:
if (nullptr = renderer)
...the code won't compile, because you've attempted to assign to a constant (whereas if (renderer = nullptr)
could compile and do the wrong thing, though most current compilers will at least give a warning about it).
Prefer nullptr
to NULL
Pretty much self-explanatory. In C++, NULL
is required to be an integer constant with the value 0
(e.g., either 0
or 0L
). nullptr
is a bit more special--it can convert to any pointer type, but can't accidentally be converted to an integer type. So, anywhere you might consider using NULL
, you're almost certainly better off using nullptr
:
if (renderer == nullptr)
Prefer nullptr
to NULL
Pretty much self-explanatory. In C++, NULL
is required to be an integer constant with the value 0
(e.g., either 0
or 0L
). nullptr
is a bit more special--it can convert to any pointer type, but can't accidentally be converted to an integer type. So, anywhere you might consider using NULL
, you're almost certainly better off using nullptr
:
if (renderer == nullptr)