Home >Backend Development >C#.Net Tutorial >Characteristics of Accessor function in C++
c is an object-oriented programming language, and one of its features is the concept of encapsulation. With encapsulation, programmers define labels for data members and functions and specify whether they are accessible by other classes. When programmers mark data members as "private", they cannot be accessed and manipulated by member functions of other classes. Accessor allows access to these private data members.
Accessor function
The access function and mutator function in c are similar to the set and get functions in c#. They are used as an alternative to making a class member variable public and changing it directly in the object. To access private object members, the Accessor function must be called.
Usually, for members such as Level, the function GetLevel() returns the value of Level, and SetLevel() assigns a value to it.
Characteristics of the Accessor function
Accessor requires no parameters
Accessor has the same type as the retrieved variable
Accessor's The name begins with the Get prefix
The naming convention is necessary
Mutator function
Although the Accessor function makes the data member accessible, it does not make the data Members can edit. Modifying protected data members requires a mutator function.
Because they provide direct access to protected data, mutator and accessor functions must be written and used with care.
Related recommendations: "C Tutorial"
The above is the detailed content of Characteristics of Accessor function in C++. For more information, please follow other related articles on the PHP Chinese website!