Characteristics of Accessor function in C++
Mar 22, 2019 pm 04:53 PMc 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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the alternatives to NULL in C language

Is NULL still important in modern programming in C language?

Method of copying code by C language compiler

What are the web versions of C language compilers?

C language online programming website C language compiler official website summary

C language compiler installation tutorial (computer version)
