Defining Classes and Member Functions

  1. A class is a data type whose variables are objects.

  2. An object is a variable that has member variables to hold values and member functions to manipulate and process those values.

  3. A class can be obtained from a structure by adding the prototypes and definitions of some member functions.

  4. In addition, keywords public or private are used to specify whether a class member function or class variable is public or private.

  5. Public class member functions and variables are directly accessible anywhere in the program.

  6. Private class member function and variables cannot be directly accessed in the program except within the definition of a member function of that class.

  7. A structure is like a class with no member functions and whose member variables are all public by default.

  8. Objects of a class type are declared in the same way as variables of the predefined type.

  9. Member functions for classes are called using the dot operator as described in chapter 5 for predefined classes such as ifstream and ofstream.

  10. A member function of a class is defined the same way as any other functions except that the class name and the scope resolution operator :: must be given in the member function heading.

  11. Two or more different classes may have member functions with the same name. They are treated as distinct member functions.

  12. Member variables belonging to the same class can be used within the definition of a member function of the class, but the dot operator cannot be used.

  13. Combining a number of related items, such as variables and functions that use these variables into a single package, such as an object of a class, is called encapsulation.