| Start |
|---|
| Const local variables Declaration and usage. Binding of references and pointers |
Const pointers |
| Const member functions Member functions of a class can be declared In a You should almost always mark member functions as
|
| Avoiding duplication of code in const and non-const getter methods. In C++ methods that differs only by Let The only difference between them is that one method is non-const and return a non-const reference (that can be use to modify object) and the second is const and returns const reference. To avoid the code duplication, there is a temptation to call one method from another. However, we can not call non-const method from the const one. But we can call const method from non-const one. That will require as to use 'const_cast' to remove the const qualifier. The solution is: In code above, we call const version of Examine the following more complete example: Syntax
RemarksA variable marked as 1: Well, it can be changed through |
Read Article
https://develop.horje.com/learn/1434/reference