Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in or
create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision |
Your text |
Line 87: |
Line 87: |
| ==== #ifdef directives ==== | | ==== #ifdef directives ==== |
|
| |
|
| Indent code that follows a conditional processor directive such as {{codeline|#ifdef}} or {{codeline|#else}}. | | Indent code that follows a conditional processor directive such as {{codeline|#ifdef}} or {{codeline|else}}. |
|
| |
|
| Example | | Example |
Line 97: |
Line 97: |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
| The '#' character may also be placed with the directive rather than remaining in column 1 if this looks better. | | The '#' character may also be placed with the directive rather than remaining in column 1. |
|
| |
|
| ==== Split long expressions ==== | | ==== Split long expressions ==== |
Line 327: |
Line 327: |
| </syntaxhighlight> | | </syntaxhighlight> |
| |} | | |} |
|
| |
| === new/delete ===
| |
|
| |
| Pointers that will be allocated memory with {{codeline|new}} should be initialized with the C++ literal {{codeline|nullptr}}, not the numerical value 0 or the macro {{codeline|NULL}}.
| |
|
| |
| The {{codeline|delete}} keyword accepts {{codeline|nullptr}} and programmers should not put an {{codeline|if (ptr)}} guard around {{codeline|delete}}.
| |
|
| |
| {| class="wikitable"
| |
| ! style="color:green;" | good
| |
| ! style="color:darkred;" | bad
| |
| |-
| |
| | <syntaxhighlight lang="c++">
| |
| delete ptr;
| |
| </syntaxhighlight>
| |
| | <syntaxhighlight lang="c++">
| |
| if (ptr)
| |
| delete ptr;
| |
| </syntaxhighlight>
| |
| |}
| |
|
| |
| === lambda expressions ===
| |
|
| |
| When capturing variables from the surrounding function, explicitly list the variables being captured rather than relying on a default capture by value (`[=]`) or by reference (`[&]`). This more clearly captures the programmer's intent and makes the code more understandable.
| |
|
| |
|
| === std::string === | | === std::string === |