Q:

When should reference parameters be references to const? What happens if we make a parameter a plain reference when it could be a reference to const

0

When should reference parameters be references to const? What happens if we make a parameter a plain reference when it could be a reference to const?

// despite appearances, these three declarations of print are equivalent
// each function has a single parameter of type const int*
void print(const int*);
void print(const int[]); // shows the intent that the function takes an
array
void print(const int[10]); // dimension for documentation purposes (at
best)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

If the reference parameters will not be changed inside function, then they should be reference to `const`.

If we make a parameter a plain reference, then we can not pass

 - a `const` object,

 - or a literal,

 - or an object that requires conversion to a plain reference parameter.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now