Science, Tech, Math › Computer Science Characteristics of Accessor Functions in C++ An accessor function allows access to private data members in C++ Share Flipboard Email Print AlexSava / Getty Images Computer Science C & C++ Programming PHP Programming Perl Python Java Programming Javascript Programming Delphi Programming Ruby Programming Visual Basic View More By David Bolton David Bolton Computer Science Expert B.A., Computer Science, Queen's University Belfast David Bolton is a software developer who has worked for several major firms, including Morgan Stanley, PwC, BAE Systems, and LCH. Learn about our Editorial Process Updated on March 13, 2019 One of the characteristics of C++, which is an object-oriented programming language, is the concept of encapsulation. With encapsulation, a programmer defines labels for the data members and functions and specifies whether they are accessible by other classes. When the programmer labels data members "private," they cannot be accessed and manipulated by member functions of other classes. Accessors allow access to these private data members. Accessor Function An accessor function in C++ and the mutator function are like the set and get functions in C#. They are used instead of making a class member variable public and changing it directly within an object. To access a private object member, an accessor function must be called. Typically for a member such as Level, a function GetLevel() returns the value of Level and SetLevel() to assign it a value. Characteristics of an Accessor Function An accessor doesn't need argumentsAn accessor has the same type as the retrieved variableThe name of the accessor begins with the Get prefixA naming convention is necessary Mutator Function While an accessor function makes a data member accessible, it does not make it editable. Modification of a protected data member requires a mutator function. Because they provide direct access to protected data, mutator and accessor functions must be written and used carefully. Cite this Article Format mla apa chicago Your Citation Bolton, David. "Characteristics of Accessor Functions in C++." ThoughtCo, Feb. 16, 2021, thoughtco.com/definition-of-accessor-958008. Bolton, David. (2021, February 16). Characteristics of Accessor Functions in C++. Retrieved from https://www.thoughtco.com/definition-of-accessor-958008 Bolton, David. "Characteristics of Accessor Functions in C++." ThoughtCo. https://www.thoughtco.com/definition-of-accessor-958008 (accessed May 29, 2023). copy citation