Possible Duplicate:
Use of 'const' for function parameters
For example,
void Func(int para);
If I know I don’t want to change para’s value in Func(…), should I instead declare para as “const int” to guarantee that? i.e.
void Func(const int para);
BTW, I think
void Func(const int ¶);
is not an appropriate alternative sometimes because const int& is usually implemented by underlying pointer, thus it is essentially equivalent to
void Func(const int *p_para);
The book “C++ Coding Standards: 101 Rules” p31 says that “void Func(const int para);” is bad as it will “confuse” the readers of the header files. I’m not sure though…
After thought it over, I think a good solution is to declare it as “void Func(int para);” and use “void Func(const int para) {…}” when implement it. I find that the word “const” in “void Func(const int para);” will be silently dropped by the compiler…
If you do this at all (and some people do) then you should put the const in the definition (where it is useful) but not the declaration (where it is noise, it doesn’t affect the caller).
So: