Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

#Object Usage

Object Usage

#Object Usage

Object Usage

added 413 characters in body
Source Link
Jerry Coffin
  • 34.1k
  • 4
  • 77
  • 145

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).

added 418 characters in body
Source Link
Jerry Coffin
  • 34.1k
  • 4
  • 77
  • 145

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)
Loading
Source Link
Jerry Coffin
  • 34.1k
  • 4
  • 77
  • 145
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /