Aim pointers (base, derived) at objects (base, derived)
- Base pointer aimed at base object
- Derived pointer aimed at derived object; both straightforward
- Base pointer aimed at derived object
- "is a" relationship; Circle "is a" Point
- Will invoke base class functions
- Function call depends on the class of the pointer/handle
- Does not depend on object to which it points
- With virtual functions, this can be changed (more later)
Figure 1:
Point class header file.
|
Figure 2:
Point class represents an xy-coordinate pair.
|
Figure 3:
Circle class header file.
|
Figure 4:
Circle class that inherits from class Point.
|
Figure 5:
Assigning addresses of base-class and derived-class objects to
base-class and derived-class pointers. (part 1 of 2)
|
Figure 6:
Assigning addresses of base-class and derived-class objects to
base-class and derived-class pointers. (part 2 of 2)
|
2004-07-26