February 2005
Beginner to intermediate
272 pages
4h 53m
English
Technically, const member functions are trivial. Socially, they can be complex.
The type of the this pointer in a non-const member function of a class X is X * const. That is, it’s a constant pointer to a non-constant X (see Const Pointers and Pointers to Const [7, 21]). Because the object to which this refers is not const, it can be modified. The type of this in a const member function of a class X is const X * const. That is, it’s a constant pointer to a constant X. Because the object to which this refers is const, it cannot be modified. That’s the difference between const and non-const member functions.
This is why it’s possible to change the logical state of an object with a const member function ...
Read now
Unlock full access