Figure 4.15:
Point2 class represents an xy-coordinate pair as protected data.
|
Figure 4.16:
Circle3 class header file.
|
Figure 4.17:
Circle3 class that inherits from class Point2.
|
Figure 4.18:
Protected base-class data can be accessed from derived class. (part 1 of 2)
|
Figure 4.19:
Protected base-class data can be accessed from derived class. (part 2 of 2)
|
Using protected data members
- Advantages
- Derived classes can modify values directly
- Slight increase in performance; avoid set/get function call overhead
- Disadvantages
- No validity checking; derived class can assign illegal value
- Implementation dependent
- Derived class member functions more likely dependent on base class implementation
- Base class implementation changes may result in derived class modifications; fragile (brittle) software
2004-07-29