25. Take parameters appropriately by value, (smart) pointer, or reference
Summary
Parameterize well: Distinguish among input, output, and input/output parameters, and between value and reference parameters. Take them appropriately.
Discussion
Choosing well among values, references, and pointers for parameters is good habit that maximizes both safety and efficiency.
Although efficiency should not be our primary up-front concern (see Item 8), neither should we write needlessly inefficient code when all other things, including clarity, are equal (see Item 9).
Prefer to follow these guidelines for choosing how to take parameters. For input-only parameters:
• Always const
-qualify all pointers or references to input-only parameters.
• Prefer taking ...
Get C++ Coding Standards: 101 Rules, Guidelines, and Best Practices now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.