C++ style guide: Difference between revisions

Jump to navigation Jump to search
276 bytes added ,  7 December 2020
m
Add recommendation on type casting.
m (Add recommendation on type casting.)
Line 192: Line 192:
* Do not use {{codeline|auto}} unless the type really is obscure.
* Do not use {{codeline|auto}} unless the type really is obscure.
* Beware of copy when using {{codeline|auto}} in for loops. Pass by reference and use {{codeline|const}} unless you're dealing with simple types such as {{codeline|int}}. See [http://lists.gnu.org/archive/html/octave-maintainers/2016-06/msg00144.html 'auto' uses and for-range loops] on the maintainers mailing list for more details.
* Beware of copy when using {{codeline|auto}} in for loops. Pass by reference and use {{codeline|const}} unless you're dealing with simple types such as {{codeline|int}}. See [http://lists.gnu.org/archive/html/octave-maintainers/2016-06/msg00144.html 'auto' uses and for-range loops] on the maintainers mailing list for more details.
=== C++ style casting ===
Always use one of the four C++ long style casting forms ({{codeline|static_cast, dynamic_cast, reinterpret_cast, const_cast}}) rather than C-style forms (type cast {{codeline|(new_type) variable}} or function form {{codeline|new_type (variable)}}.


=== C++14 ===
=== C++14 ===
1,072

edits

Navigation menu