- Previous example
- Aimed base-class pointer at derived object; Circle "is a" Point
- Aim a derived-class pointer at a base-class object
- Compiler error
- No "is a" relationship
- Point is not a Circle
- Circle has data/functions that Point does not
- setRadius (defined in Circle) not defined in Point
- Can cast base-object"s address to derived-class pointer
- Called downcasting (more in 10.9)
- Allows derived-class functionality
Figure 7:
Aiming a derived-class pointer at a base-class object.
|
2004-07-26