); // by value: the function works on a copy void (& ); // by reference: the function shares the caller's object void (const & ); // by const reference: shared, read-only, not copied ( , = ); // trailing default argument void (); // an overload set: one name, void (, ); // distinguished only by the parameter lists ~~~ | Part | Meaning | | --- | --- | | ` ` | A copy. Changes stay inside the function; safe, but costs a copy. | | `& ` | An alias for the caller's object. Writes are visible outside, so the caller must expect them. | | `const & ` | No copy and no mutation. The default for anything large you only need to read. | | `= ` | Defaults must be trailing, and are written on the declaration only, never repeated on the definition. | | overloading | Parameter lists must differ. A different return type alone is not enough and will not compile. | Choose the parameter-passing mechanism from what the function does with the argument: pass by value for a small input, by const reference to read only, and by reference only when the caller expects the argument to be modified.
); // by reference: the function shares the caller's object void (const & ); // by const reference: shared, read-only, not copied ( , = ); // trailing default argument void (); // an overload set: one name, void (, ); // distinguished only by the parameter lists ~~~ | Part | Meaning | | --- | --- | | ` ` | A copy. Changes stay inside the function; safe, but costs a copy. | | `& ` | An alias for the caller's object. Writes are visible outside, so the caller must expect them. | | `const & ` | No copy and no mutation. The default for anything large you only need to read. | | `= ` | Defaults must be trailing, and are written on the declaration only, never repeated on the definition. | | overloading | Parameter lists must differ. A different return type alone is not enough and will not compile. | Choose the parameter-passing mechanism from what the function does with the argument: pass by value for a small input, by const reference to read only, and by reference only when the caller expects the argument to be modified.
); // by const reference: shared, read-only, not copied ( , = ); // trailing default argument void (); // an overload set: one name, void (, ); // distinguished only by the parameter lists ~~~ | Part | Meaning | | --- | --- | | ` ` | A copy. Changes stay inside the function; safe, but costs a copy. | | `& ` | An alias for the caller's object. Writes are visible outside, so the caller must expect them. | | `const & ` | No copy and no mutation. The default for anything large you only need to read. | | `= ` | Defaults must be trailing, and are written on the declaration only, never repeated on the definition. | | overloading | Parameter lists must differ. A different return type alone is not enough and will not compile. | Choose the parameter-passing mechanism from what the function does with the argument: pass by value for a small input, by const reference to read only, and by reference only when the caller expects the argument to be modified.
, = ); // trailing default argument void (); // an overload set: one name, void (, ); // distinguished only by the parameter lists ~~~ | Part | Meaning | | --- | --- | | ` ` | A copy. Changes stay inside the function; safe, but costs a copy. | | `& ` | An alias for the caller's object. Writes are visible outside, so the caller must expect them. | | `const & ` | No copy and no mutation. The default for anything large you only need to read. | | `= ` | Defaults must be trailing, and are written on the declaration only, never repeated on the definition. | | overloading | Parameter lists must differ. A different return type alone is not enough and will not compile. | Choose the parameter-passing mechanism from what the function does with the argument: pass by value for a small input, by const reference to read only, and by reference only when the caller expects the argument to be modified.
= ); // trailing default argument void (); // an overload set: one name, void (, ); // distinguished only by the parameter lists ~~~ | Part | Meaning | | --- | --- | | ` ` | A copy. Changes stay inside the function; safe, but costs a copy. | | `& ` | An alias for the caller's object. Writes are visible outside, so the caller must expect them. | | `const & ` | No copy and no mutation. The default for anything large you only need to read. | | `= ` | Defaults must be trailing, and are written on the declaration only, never repeated on the definition. | | overloading | Parameter lists must differ. A different return type alone is not enough and will not compile. | Choose the parameter-passing mechanism from what the function does with the argument: pass by value for a small input, by const reference to read only, and by reference only when the caller expects the argument to be modified.
` | A copy. Changes stay inside the function; safe, but costs a copy. | | `& ` | An alias for the caller's object. Writes are visible outside, so the caller must expect them. | | `const & ` | No copy and no mutation. The default for anything large you only need to read. | | `= ` | Defaults must be trailing, and are written on the declaration only, never repeated on the definition. | | overloading | Parameter lists must differ. A different return type alone is not enough and will not compile. | Choose the parameter-passing mechanism from what the function does with the argument: pass by value for a small input, by const reference to read only, and by reference only when the caller expects the argument to be modified.
` | An alias for the caller's object. Writes are visible outside, so the caller must expect them. | | `const & ` | No copy and no mutation. The default for anything large you only need to read. | | `= ` | Defaults must be trailing, and are written on the declaration only, never repeated on the definition. | | overloading | Parameter lists must differ. A different return type alone is not enough and will not compile. | Choose the parameter-passing mechanism from what the function does with the argument: pass by value for a small input, by const reference to read only, and by reference only when the caller expects the argument to be modified.
` | No copy and no mutation. The default for anything large you only need to read. | | `= ` | Defaults must be trailing, and are written on the declaration only, never repeated on the definition. | | overloading | Parameter lists must differ. A different return type alone is not enough and will not compile. | Choose the parameter-passing mechanism from what the function does with the argument: pass by value for a small input, by const reference to read only, and by reference only when the caller expects the argument to be modified.
const
Setup The caller sends a value into a function.
Punchline Copy it for a souvenir; alias it if you mean to change the original.
row
column
main
Setup The function needs to look, not rearrange.
Punchline "Hands off, I am only reading" — no copy, no touch.
Setup Two functions want the same name badge.
Punchline Different inputs earn different doors; a different return alone does not.
const&