Accessors and Mutators C++

Accessors and Mutators C++

Please note that this is basic C++.

Accessor – Member function used to retrieve the data of protected members.

Mutators – Member function used to edit the data of protected members.

In your case,

class Customer
    string getName(); // Accessor for the m_name variable
    void editName(string in); // Mutator for the m_name variable

    string m_name;
    int m_age;


Inside your .cpp file:

string Customer::getName() {
    return m_name;

void Customer::editName(string in) {
    m_name = in;

Accessors and Mutators C++

Leave a Reply

Your email address will not be published.