1 3 C + + C C + + 13.1 X
256 C + + p r i v a t e p u b l i c p e r m u t e () X X Y 13.2 Y Y X
13 257 Y X Y X X m a i n () s i z e o f ( Y s i z e o f ( X ) p u b l i c p r i v a t e p u b l i c p r i v a t e p u b l i c p u b l i c p u b l i c h a n g e () p e r m u t e () p u b l i c s e t () s e t () Y r e a d () p e r m u t e () m a i n ( Y s e t () c h a n g e () s e t ()
258 C + + 13.3 C + + p r i v a t e C + + b a r f o o bar i n t foo::foo(int i) : bar(i) { //... 13.3.1 foo2:foo2(int I) : bar(i), memb(i+1) { //... foo2 bar memb 13.3.2 C + +
13 259 int i(100); 13.4
260 C + + C B A C::f() B :: f () a. f ( C::f() C f() a. f () B :: f ( 13.4.1
13 261 ofstream 18 13.4.2
262 C + + bart d o h () bart, milhouse 13.4.3 operator= 11 operator=
13 263 operator= operator other() root other derived root f() other main() root derived operator=( ) root other root 13.5
264 C + + private p u b l i c Car
13 265 i s - a has-a 13.5.1 ifstream ifstream strstream fname1 ifstream & ifstream fname1 main
266 C + + c o u t < < f i l e. r d b u f ( ) < < e n d l ; fname1 rdbuf() filebuf * rdbuf() {return File.rdbuf();} ifsream
13 267 ofstream fname2 fname2 o f s t r e a m 14 13.5.2 stack stack S T R I N G S. H 12. 2. 1 S TA C K 11.H 1 2. 2. 3 12
268 C + + S TA C K 11.OBJ s t r i n g l i s t stack p u s h () s t r i n g s t a c k v o i d p e e k () p o p () s t r i n g v o i d 12 s t a c k :: ~ s t a c k () d e l e t e v o i d d e l e t e v o i d s t r i n g l i s t :: ~ s t r i n g l i s t () s t r i n g d e l e t e 1) stack p r o t e c t e d s t r i n g l i s t p r o t e c t e d 2) s t a c k 3) s t r i n g s t r i n g l i s t 15 13.5.3 public p r i v a t e 13. 5. 1 F N A M E 2. C P P private p r i v a t e p r i v a t e p r i v a t e p r i v a t e p r i v a t e p u b l i c p r i v a t e p u b l i c
13 269 p r i v a t e p r i v a t e 18 13.6 p r o t e c t e d p r i v a t e p r o t e c t e d p r i v a t e p r i v a t e C S S H A P E p r o t e c t e d
270 C + + p r i v a t e p u b l i c p r i v a t e p u b l i c p r o t e c t e d i s - a 13.7 16 13.8 13.9 ofstream ofstream 13.5.1 FNAME2.CPP ofstream fname2
13 271 i n s t r u m e n t w i n d i n s t r u m e n t p l a y () wind w i n d instrument t u n e () i n s t r u m e n t m a i n () t u n e () w i n d C + + w i n d i n s t r u m e n t t u n e () instrument w i n d t u n e () i n s t r u m e n t i n s t r u m e n t w i n d i n s t r u m e n t 13.9.1 W I N D. C C P 17
272 C + + 13.9.2 s t a c k s t r i n g l i s t s t r i n g I N H S TA C K. C P P ( 13. 5. 2 ) s t a c k s t r i n g l i s t s t r i n g l i s t p r i v a t e s t r i n g l i s t
13 273 13.9.3 W I N D. C P P ( 13. 9 ) w i n d i n s t r u m e n t 13.9.4 wind w; instrument * ip = &w; i p i n s t r u m e n t i p w i n d p l a y () i p - > p l a y ( m i d d l e C ) ; i n s t r u m e n t p l a y () i n s t r u m e n t p l a y () w i n d p l a y () C + + v i r t u a l 13.10 13.11 1. C A R. C P P v e h i c l e v e h i c l e v e h i c l e c a r 2. A B A C C B C C 3. 12 P S TASH.H & PSTA S H. C P P p s t a s h S t r i n g P S T E S T. C P P p s t a s h 4. p r i v a t e p r o t e c t e d