In OOP, member functions are functions which are a part of a class, rather than having global scope. They are subject to normal access controls, which means some are public and some are private.

Member functions are typically used for manipulating the data members of a class, especially the private ones. Private data members cannot be manipulated by any other part of the program, and member functions are there to make sure nothing illegal or likely to break the object is done. Private data members of a class are usually accessed and set through member functions, so range checking and anything else required can be performed.

Member functions are, in the spirit of encapsulation, the black box through which a program can interface with a class. The program (or programmer) does not need to know about the classes' inner workings, just what member functions to use for what.

A true OOP system would have no global functions whatsoever, and be made up entirely of member functions that were a part of classes. Member functions are a good way of performing actions on structs of data, especially in C++. In C, the old way of performing an action on a struct was to have a global function that accepted a pointer to the struct as an argument.

Log in or register to write something here or to contact authors.