1. Home
  2. Computing & Technology
  3. C / C++ / C#

Definition of Accessor

By David Bolton, About.com

Definition: An accessor function in C++ is like the getter and setter functions in C#. This is used instead of making a class member variable public and changing it directly within an object, It is made private and not directly accessible. To read or modify the object member, an accessor function must be called.

Typically for a member such as Level, a function GetLevel() would return the value of Level and SetLevel() to assign it a value.

class CLevel {
private:
int Level;
public:
int GetLevel() {return Level;} ;
void SetLevel(int NewLevel) { Level=NewLevel;} ;

};

Glossary:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Explore C / C++ / C#
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

©2009 About.com, a part of The New York Times Company.

All rights reserved.