Contents Up << >>

What is a "const member function"?

A member function that inspects (rather than mutates) its object.

  	class Fred {
	public:
	  void f() const;
	};      // ^^^^^--- this implies "fred.f()" won't change "fred"
This means that the abstract (client-visible) state of the object isn't going to change (as opposed to promising that the "raw bits of the object's struct aren't going to change). C++ compilers aren't allowed to take the "bitwise" interpretation, since a non-const alias could exist which could modify the state of the object (gluing a "const" ptr to an object doesn't promise the object won't change; it promises only that the object won't change via that pointer).

"const" member functions are often called "inspectors." Non-" const" member functions are often called "mutators."