TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C++

C++ Accessor & Mutator Member Functions

Overview

In this tutorial, we will learn about C++ Accessor & Mutator Member Functions. We use these methods to access or modify the private data members of a class from the code outside the class.

Accessor Member Function

The accessor member function gets the value of a private data member of the class.

This method is also known as Get or Getter method.

C++ Accessor Member Functions

//C++ Accessor Member Function
 string getName()
 {
 return name; // return employees's name
 }

Mutator Member Function

The mutator member function sets a new value to the private data member of the class. There are other use cases where we use the mutator method to clean or ensure that the private data variable can only have valid data.

This method is also known as Set orĀ Setter method.

C++ Mutator Member Functions

 

//C++ Mutator Member Function
 void setName(string name)
 {
 this->name = name;// set employees's name
 }

—

C++ Tutorials

C++ Tutorials on this website:

https://www.testingdocs.com/c-coding-tutorials/

For more information on the current ISO C++ standard

https://isocpp.org/std/the-standard

Related Posts

g not found OpenSuse

C++ /

Install GCC C++ Compiler on OpenSuse

sum of digits c program

C++ /

Sum of Digits of a Number C++ Program

C++ Hello World Program

C++ /

C++ Hello World Program

C++ /

Object-Oriented Programming Language Examples

C++ /

Object-Oriented Programming Features

‹ C++ Access Modifiers› C++ Increment Operator

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version