Should you pass objects by const reference as a function parameter?
Show answer and explanation
Use const T& for a required, non-owning read-only parameter when copying T is expensive. Use T when the function needs its own value, T& for mutation, and pointer-like forms when nullability or ownership must be expressed.
Use const T& for a required, non-owning read-only parameter when copying T is expensive. Use T when the function needs its own value, T& for mutation, and pointer-like forms when nullability or ownership must be expressed.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.