There are three strong reasons to declare reference arguments as references to constant data:
- Using const protects you against programming errors that inadvertently alter data
- Using const allows a function to process both const and non-const actual arguments, whereas a function that omits const in the prototype only can accept non-const data.
- Using a const reference allows the function to generate and use a temporary variable appropriately.
You should declare formal reference arguments as const whenever it's appropriate to do so.
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten