Make abstract base class Shape
- Pure virtual functions (must be implemented)
- getName, print
- Default implementation does not make sense
- Virtual functions (may be redefined)
- getArea, getVolume; initially return 0.0
- If not redefined, uses base class definition
- Derive classes Point, Circle, Cylinder
Figure 5.13:
Defining the polymorphic interface for the Shape hierarchy classes.
|
Figure 5.14:
Abstract base class Shape header file and Abstract base class Shape.
|
Figure 5.15:
Point class header file.
|
Figure 5.16:
Point class implementation file. (part 1 of 2)
|
Figure 5.17:
Point class implementation file. (part 2 of 2)
|
Figure 5.18:
Circle class header file and Circle class that inherits from
class Point. (part 1 of 2)
|
Figure 5.19:
Circle class that inherits from class Point. (part 2 of 2)
|
Figure 5.20:
Cylinder class header file.
|
Figure 5.21:
Cylinder class implementation file. (part 1 of 2)
|
Figure 5.22:
Cylinder class implementation file. (part 2 of 2)
|
Figure 5.23:
Demonstarting polymorphism via a hierarchy headed by an abstract base class. (part 1 of 3)
|
Figure 5.24:
Demonstarting polymorphism via a hierarchy headed by an abstract base class. (part 2 of 3)
|
Figure 5.25:
Demonstarting polymorphism via a hierarchy headed by an abstract base class. (part 3 of 3)
|
2004-07-29