This is a modifier that affects this method (it applies only to methods). This means that it will be available, but does not change the state of the object (i.e., no attributes will be changed).
Another subtle change is that this method can only call other const
methods (it would be pointless to allow it to call methods that are likely to modify the object). Sometimes this means that you need two versions of some methods: const
and not const
.
source share