August 2001
Beginner
482 pages
10h 52m
English
It is not uncommon to build up a complex class by declaring simpler classes and including them in the declaration of the more complicated class. For example, you might declare a Wheel class, a Motor class, a Transmission class, and so forth, and then combine them into a Car class. This declares a has-a relationship: A car has a motor, it has wheels, and it has a transmission.
Consider a second example. A rectangle is composed of lines. A line is defined by two points. A point is defined by an x coordinate and a y coordinate. Listing 8.3 shows a complete declaration of a Rectangle class as it might appear in RECTANGLE.HPP. Because a rectangle is defined as four lines connecting four points, and each point ...
Read now
Unlock full access