Home Backend Development C#.Net Tutorial Characteristics of Accessor function in C++

Characteristics of Accessor function in C++

Mar 22, 2019 pm 04:53 PM

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.

Characteristics of Accessor function in C++

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add next-level C compiler How to add next-level C compiler Mar 03, 2025 pm 05:44 PM

How to add next-level C compiler

What are the alternatives to NULL in C language What are the alternatives to NULL in C language Mar 03, 2025 pm 05:37 PM

What are the alternatives to NULL in C language

Is NULL still important in modern programming in C language? Is NULL still important in modern programming in C language? Mar 03, 2025 pm 05:35 PM

Is NULL still important in modern programming in C language?

Which C language compiler is better? Which C language compiler is better? Mar 03, 2025 pm 05:39 PM

Which C language compiler is better?

Method of copying code by C language compiler Method of copying code by C language compiler Mar 03, 2025 pm 05:43 PM

Method of copying code by C language compiler

What are the web versions of C language compilers? What are the web versions of C language compilers? Mar 03, 2025 pm 05:42 PM

What are the web versions of C language compilers?

C language online programming website C language compiler official website summary C language online programming website C language compiler official website summary Mar 03, 2025 pm 05:41 PM

C language online programming website C language compiler official website summary

C language compiler installation tutorial (computer version) C language compiler installation tutorial (computer version) Mar 03, 2025 pm 05:41 PM

C language compiler installation tutorial (computer version)

See all articles