2012年5月1日 星期二

Usage of const in C++

http://duramecho.com/ComputerInformation/WhyHowCppConst.html

1. Variables declared with ‘const’ added become constants and cannot be altered by the program.

2. One has to initialise it immediately in the constructor because, of course, one cannot set the value later as that would be altering it.


3. function returned value, function parameter passing, function itself
const int*const Method3(const int*const&)const;
where the 5 uses ‘const’ respectively mean that the variable pointed to by the returned pointer & the returned pointer itself won’t be alterable and that the method does not alter the variable pointed to by the given pointer, the given pointer itself & the object of which it is a method!.

沒有留言: