CEII Lecture 5
CEII Lecture 5
Computer Engineering II
Lecture 5
Classes
Chapter 1 introduced the problem-solving methodology called object-oriented
design (OOD). In OOD, the first step is to identify the components, called
objects. An object combines data and the operations on that data in a single
unit. In C++, the mechanism that allows you to combine data and the operations
on that data in a single unit is called a class.
The two built-in operations that are valid for class objects are member access
(.) and assignment (=).
Accessor function: A member function of a class that only accesses (that is,
does not modify) the value(s) of the member variable(s).
Because the private members of a class cannot be accessed outside of the class
(in our case, the member variables), if the user forgets to initialize these
variables by calling the function setTime, the program will produce erroneous
results.
To guarantee that the member variables of a class are initialized, you use
constructors. There are two types of constructors: with parameters and
without parameters. The constructor without parameters is called the default
constructor.