An object is a typed region of storage in the execution environment; in addition to retaining state information, it also defines behavior. Class-type objects are defined using class-name. Consider the following code fragment:
class Account // Class name is Account.
{
public:
Account(); // Default constructor.
Account( double ); // Construct from double.
double& Deposit( double );
double& Withdraw( double, int );
...
}:
Account CheckingAccount; // Define object of class type.
The preceding code declares a class (a new type) called Account
. It then uses this new type to define an object called CheckingAccount
.
The following operations are defined by C++ for objects of class type:
The following are examples of initialization using user-defined copy constructors:
Point myPoint = thatPoint;
declares myPoint
as an object of type Point
and initializes it to the value of thatPoint
.
Overloaded Operators in Chapter 12 explains how to redefine other operators on a class-by-class basis.