Figure 15:
Point2 class represents an xy-coordinate pair as protected data.
|
Figure 16:
Circle3 class header file.
|
Figure 17:
Circle3 class that inherits from class Point2.
|
Figure 18:
Protected base-class data can be accessed from derived class. (part 1 of 2)
|
Figure 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-22