accessor/ mutator functions what are they and what do they do?...can't find it in the book.
accessor/ mutator functions what are they and what do they do?...can't find it in the book.
accessors return private data members.
mutators, also called modifiers, modify private data.
this is within a class.
and is usually used for private data members, at least to maintain encapsulation.
i.e.
if you have a class with private int data;
an accessor with be similar to this:Code:int data;
a mutator will be something like this:Code:int get_data() const //preferable to keep this const //because it does not modify data members { return data; }
Code:void set_data(int temp_data) { data = temp_data; }
They are also called get methods "getters" and set methods "setters"
Mr. C: Author and Instructor