Constant class member functions
suggest changeVersions
Remarks
What does a const member function of a class really mean? A const member function cannot modify the object it is called on. That includes assigning to a non-mutable data member and calling a non-const member function.
It can still modify an object reached through a pointer or reference member, as in the example. The pointer member itself is unchanged, so writing into the map is well-formed. That still changes the program’s logical state. A mutable member may also be assigned.
delete on that pointer is well-formed in a const function, but it leaves the pointer dangling. Assigning a new pointer to the member is ill-formed.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents