C++ Language/Objects/ConstMembers/ConstMemberFunctions

From Wikibooks, open books for an open world
Jump to navigation Jump to search

A member function automatically has access to a this pointer variable whose type is CRType* and which is automatically pointing at the CRType object being manipulated by this member function. But you could have defined the member function as void CRType::DoAction() const {body}, in which case the type of this becomes const CRType* (that function's body can view data members but not alter them).

This restriction can be ignored for individual data members (on a case-by-case basis) but marking the data member with mutable.

Additional information about const member functions