It means that this function does not modify the observable state of an object.
In compiler terms, it means that you cannot call a function on a const
object (or const reference or const pointer) unless that function is also declared to be const
. Also, methods which are declared const
are not allowed to call methods which are not.
Update: as Aasmund totally correctly adds, const
methods are allowed to change the value of members declared to be mutable
.
For example, it might make sense to have a read-only operation (e.g. int CalculateSomeValue() const
) which caches its results because it's expensive to call. In this case, you need to have a mutable
member to write the cached results to.
I apologize for the omission, I was trying to be fast and to the point. :)