Justification for the implementation of the secure access specifier

What was the rationale for introducing a secure access specifier in C ++. An example will be helpful.

+5
source share
2 answers

The access level is protectedused when classes must work with their descendants.

For example, imagine an abstract Shapeclass that can communicate its area to the outside world.

Various shapes, such as triangles, squares, and circles, are described differently (angle, side, radius) and their areas are calculated differently.

Shape getArea(), , .
- protected, setArea(double), .

, Circle setArea(PI * radius * radius), Square setArea(side * side) ..

, ( protected)

+2

" " ++ by Bjarne Stroustrup. 13.9 .

1.0 [of Cfront] [...] , X-. [...] , , , . [...]

[ X-Windows, ], . [...] [...]

1.2. 2.1. , protected - , " " .

+3

All Articles