What is the difference between an inspector and a mutator ?

chinmay.sahoo

New member
An inspector is a member function that returns information about an object's state (information
stored in object's data members) without changing the object's state. A mutator is a member function
that changes the state of an object. In the class Stack given below we have defined a mutator and an
inspector.

class Stack
{
public :
int pop( ) ;
int getcount( ) ;
}

In the above example, the function pop( ) removes top element of stack thereby changing the state of an object. So, the function pop( ) is a mutator. The function getcount( ) is an inspector because it simply counts the number of elements in the stack without changing the stack.
 
Back
Top