C++ Class Member Function Types
C++ classes consist of data members and member functions.
Member functions fall into different categories based on the services
they provide to the class.
- Initialization Functions set the initial values of some or all
data members of the class. These member functions set the stage for a class
instance to start out in the proper state. One special case of this
type of member function is the class constructor.
- Data Broker Functions convert data and perform other data
management operations. A data broker function may allocate dynamic memory
needed by a class instance and/or convert data from one type to another.
Data broker functions support other member functions in the same class.
- Implementation Functions perform the main operations of the class.
These functions can modify the values of the data members and thereby
alter the state of an instance of the class. Implementation functions
change values of data members, sometimes performing calculations in the
process.
- Access Functions allow a class instance to access some or all
of the data members in the class. These member functions ensure that the
class instances do not have direct access to critical data members, thereby
avoiding possibley corrupting their data. These functions fall into three
subcategories:
- Get Functions return the values of data members.
- Set Functions write new values to data members. Set functions
must check input data to ensure that the data members are set to legal values.
- Modified Set Functions write new values to data members and
also return the old values of these data members.
- Auxilary Functions are helper functions that assist the other
kinds of member functions in performing their tasks. The auxiliary
member functions usually work behind the scenes, so to speak. Sometimes
they are called Utility Functions.
- const Functions ensure that the code defining them does not
alter the value of any data member. The most common example of a const
function is the Get Function.