Example: Avoid
const
pass-by-value function parameters in function declarations. The following two declarations are exactly equivalent:
void Fun( int x ); void Fun(
const int x );
// redeclares the same function: top-level const is ignored
In the second declaration, the
const is redundant. We recommend declaring functions without such top-level
const s, so that readers of your header files won't get confused. However, the top-level
const does make a difference in a function's
definition and can be sensible there to catch unintended changes to the parameter:
void Fun( const int x ) {
// Fun's actual definition
// … ++x;
// error: cannot modify a const value
// … }