Thread: accessor/ mutator functions ??

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    82

    accessor/ mutator functions ??

    accessor/ mutator functions what are they and what do they do?...can't find it in the book.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    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;

    Code:
    int data;
    an accessor with be similar to this:
    Code:
    int get_data() const //preferable to keep this const
    //because it does not modify data members
    {
      return data;
    }
    a mutator will be something like this:
    Code:
    void set_data(int temp_data)
    {
      data = temp_data;
    }

  3. #3
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Smile

    They are also called get methods "getters" and set methods "setters"
    Mr. C: Author and Instructor

Popular pages Recent additions subscribe to a feed