Const in C++
From old CS271 notes…
Const pointers and data
T const *p;
– p is a pointer to a const T
(can be reversed: const T *p === T const *p
)
T *const p;
– p is a const pointer to T
T const *const p;
– p is a const pointer to a const T
Const methods
Placing const
after a method head and before the body
means that it does not modify the object that it is called on.
Placing const
in front of the return type means that
the value returned cannot be modified.