More Eff ective C++( MEC++),.,. 2002 11 25 2002 12 15,,.. (chapter). (seaousak@hotmail.com). (www.kwak101.pe.kr) kwak101 [MEC++ ].. (, seaousak@hotmail.com, http://seaousak.natoo.net), More Eff ective C++. C++,.
6 C++. C++ Report Dr.Dobb's Journal C/C++ User Journal C++. Effective C++, Effective More Effective. More Effective C++ Effective C++. C++. C++,.,..,,.,, C++. C++. : AV(Anti-Virus). Microsoft MVP(Most Valuable People), KBench ( ) 1997.06 ~ 1997.12 : C++, 1998.01 ~ 1998.12 Computer Club, 1998.01 ~ 1998.12 : AICC, 1999.05 ~ 2001.10 :, 2001.01 ~ : Visual C++ 2000.03 ~ :, 2001.05 : ' C# ', 2002.04 : Microsoft Visual C++.NET Step By Step, 2002.09 : Microsoft Programming.NET, 2002.10 : Micrososft Visual C#.NET Programming, 2002.11 ~ : ' ' 2002.04 : Microsoft, 2002.06 : Microsoft 2002.11 : MCAD(Microsoft Certified Application Developer) Charter Member
7 (lumina75@naver.com), Gof. MEC++,,.,..,.,,.,,, PLC, C++ Template, (nemonandes@empal.com) Effective C++, More Effective C++,.,. (chapter). More Effective C++...
8 4 /. Windows Networking 168, ALMS(Application Level Multicast System),,,, (jof4002@krpost.net, http://www.jof4002.net) C++.,.! STL...,.,,.,.... NC, 3 (jof4002)., Google...
Addison-Wesley Professional Computing(AW Prof. ). AW Prof. C++. Effective STL More Effective C++,,., (errata) ( 2001 12 12 ).,,.,.,..
14 STL STL(,, 2002),., The C++ Standard Library : Tutorial & Reference (Nicolai M. Josuttis, Addison Wesley, 1999, ) The C++ : - & (, ASCII, 2001) Effective C++ 2/E (Scott Meyers, Addison-Wesley, 1998) Effective C++ (, Ascii Addison Wesley programming series, 1998). (container), (vector, list ). ( - string, pair :,,, STL ' ) C++ (fiume620@hotmail.com, http://www.fiumewith.com) (lazy evaluation :, eager evaluation :. over-eager evaluation : ). : 1. (parameter), (argument)., ( ).. argument, parameter. 2. hierarchy (gryu@korea.com) ( ), ( ). http :/ / www.occam.com.ne.kr. 3. const.
15 - const < > * name ; : ( ) - < > * const name ; : ( ) 4. ( ),. Effective C++ More Effective C++ Effective STL EC++ MEC++ ESTL t RaNsLaTi On.. ht t p :/ /www. kwak101.pe. kr
( ) const ant t i me ( ) l i near ( ) l i near t ime ( ) l ogar i t hmi c t i me ( ) quadr at i c 80-20 rul e al gor i t hm cache chunk col l ect i on compl exi t y component directed acyclic graph di r ect ed gr aph i nt ernat i onal i zat i on i nval i dat i on i t er at i ve cal l l ocal e l ocal i t y of r ef er ence l val ue memor y l ayout ( ) ( ) 80-20,,
18 N or der of magni t ude obj ect f i l e page f aul t per si st ence pr ef et chi ng pr of i l e r esol ve rval ue scope t hr ead 10 N ( ) (, ), C+ +, (cl ass ) hi er ar chy (except i on) cat ch by r ef er ence (except i on) cat ch by val ue (obj ect ) cr eat e (obj ect ) dest r oy ( ) del et e ( ) deep copy ( ) shal l ow copy ( ) cat ch ( ) pr opagat e ( ) r et hr ow ( ) t hr ow ( ) expl i ci t t ype conver si on ( ) i mpl i ci t t ype conver si on ( ) st r ongl y t yped ( ) ( ). C++. ( ) ( ) ( ), ( ) ( ) ( ) ( ),
19 ( ) weakl y t yped ( ) eager eval uat i on ( ) l azy eval uat i on ( ) over - eager eval uat i on abst r act cl ass ar gument bui l t - i noper at or bui l t - i nt ype cal l back cal l ee cal l er cast comma operator concr et e cl ass const const ness const r uct or const r uct s (i n C++) copy- on-wr i t e der ef er ence dest ruct or eager eval uat i on except i on saf et y except i on speci f i cat i on expl i ci t expr essi on gl obal obj ect i mpl i ci t i nt ernal l i nkage l azy l i nkage l ocal obj ect,, ( ), const( ) (C++ ), COW ( ) ( ) ( C++ ), explicit (C++ ) (, )
20 member i ni t i al i zat i on l i st mi xed- t ype assi gnment mi xi n name mangl i ng nest ed non- const non-member over - eager over l oad (i ng) over r i de par amet er par t i al as si gnment pass pl acement new poi nt er post f i x pr ef i x pseudo- const r uct or pseudo- dest ruct or r aw memor y r aw poi nt er r edef i ne r ef er ence reference count (ing) r esour ce r et urn r unt i me t ype i dent i f i cat i on semant i cs shor t - cut (eval uat i on) sl i ce,, ( ), const ( ), ( ),, (, ), new ( ) ( ), C/C++ (dumb) ( ), ( ) ( ) ( ), ( )
21 sl i ci ng pr obl em smar t poi nt er speci f i cat i on speci al i ze (t empl at e ) st ack r ewi ndi ng t empor ar i es t hr ead saf et y vol at i l eness, ( ) STL STL( ) bi t set deque hash_map hash_set l i st map mul t imap mul t i set pai r r ope set sl i st st r i ng t r ai t s vect or,,,
22 STL, C + + al gor i t hm al l ocat or associ at i ve cont ai ner base i t er at or capaci t y const i t er at or dependent t ype equal i t y equi val ence f acet f orward i t er at or f unct i on obj ect f unct or gener al i zat i on gener i c hashed poi nt er i nst ance i t er at or l ocal e oper at i on pr edi cat e r andom access i t er at or r ange reverse iterator sequence t empl at e, ( ), ( ),,,
.,..,. Computer Architecture: A Quantitative Approach (Morgan Kaufmann, 1 1990) L. (John L. Hennessy) A (David A. Patterson)., 16 80-20.,.,.,. comp. l ang. c++ comp. st d. c++. C++.,.
24 (Brian Kernighan) 1) C++, 2. 3, (Dan Saks) Gotchas. C++. 5 (single-argument), (Andrew Koenig) C++ Report 1994 1. (prefix) (postfix) comp. l ang. c++ (James Kanze) 6. Effective C++ (David Cok), 8 oper at or new new.,.. ( 9 ) A. (Margaret A. Ellis) (Bjarne Stroustrup)Annotated C++ Ref erence Manual( ARM. ) 15.3. (resource acquisition is initialization). (Tom Cargill). 11 Taligent's Guide to Designing Programs(Addison-Wesley, 1994) 4. 1) The C Program ming Lanuguage (Prentice- Hall 1979, 1988)Addison-Wesley Professional Computing Series
25 18, DynArray (over-eager) C++ Report 1992 6 A Dynamic vector is harder than it looks. C++ Report 1994 1. 21 1991 USENIX C++ Conference An AWK to C++ Translator. (overloading) ( 67!) 21,. 26, (Jamshid Afshar) comp. l ang. c++. oper at or new (mixin) ( 27) (Don Box) 2). (Steve Clamage), dynami c_ca st. 28 (smart pointer)., (Steven Buroff) (Rob Murray) C++ Report 1993 10R., Smart Pointers: They're Smart, but They're Not Pointers(1992 USENIX C++ Conference ) C++ Oracle, Design and Evolution of C++( ) 15.9.1, (Gregory Colvin) C/C++ Solutions 95 C++ Memory Management, (Cay Horstmann) 3) C++ Report 1993 3-4. 28.. 29, C++ Strategies and Tactics( 2) Essential COM(Addison-Wesley 1998) 3) Core Java(Prentice Hall, 1996)
26 ) 6.3.2 7.4.2. C++ Report 1993 3~4. 30 lvalue C User's Journal(C/ C++ Users Journal ) 1993 1.,. ( 31 ), comp. l ang. c++ Design and Evolution of C++( ) 13.8.1. 33 1994 1995 C++ Report., dynami c_ca st oper at or =. 34C++ Report 1992 5 Linking C++ with other languages. strdup. ( ).., ( ). (Jill Huchital), (Tim Johnson),, (Eric Nagler), (Chris Van Wyk). (Katrina Avery), (Don Box), (Steve Burkett), (Tom Cargill), (Tony Davis), (Carolyn Duby), (Bruce Ecke l) 4), (Read Fleming), (Cay Horstmann), (James Kanze),
27 (Russ Paielli), (Steve Rosenthal), (Robin Rowe), (Dan Saks), (Chris Sells), (Webb Stacy), (Dave Swift), (Steve Vinoski). (Bob Beauchaine), (Gerd Hoeren), (Jeff Jackson), L. (Nancy L. Urbano) 5)...,. Luis Kida, John Potter, Tim Uttormark, Mike Fulkerson, Dan Saks, Wolfgang Glunz, Clovis Tondo, Michael Loftus, Liz Hanks, Wil Evers, Stefan Kuhlins, Jim McCracken, Alan Duchan, John Jacobsma, Ramesh Nagabushnam, Ed Willink, Kirk Swenson, Jack Reeves, Doug Schmidt, Tim Buchowski, Paul Chisholm, Andrew Klein, Eric Nagler, Jeffrey Smith, Sam Bent, Oleg Shteynbuk, Anton Doblmaier, Ulf Michaelis, Sekhar Muddana, Michael Baker, Yechiel Kimchi, David Papurt, Ian Haggard, Robert Schwartz, David Halpin, Graham Mark, David Barrett, Damian Kanarek, Ron Coutts, Lance Whitesel, Jon Lachelt, Cheryl Ferguson, Munir Mahmood, Klaus-Georg Adams, David Goh, Chris Morley, Rainer Baumschlager, Christopher Tavares, Brian Kernighan, Charles Green, Mark Rodgers, Bobby Schmidt, Sivaramakrishnan J., Eric Anderson, Phil Brabbin, Feliks Kluzniak, Evan McLean, Julian Smith, Kurt Miller. More Effective C++ ( )., C++ ISO/ANSI 6).. (John Max Skaller) (Steve Rumsby) ANSI C++ (draft) HTML. (Vivian Neou) (16 ) HTML 4 ) Thinking in Java(Prentice Hall, 1998) 5) 6). 1996
28 WWW. HTML. (Bryan Hobbs) (Hachemi Zenad) (MetaWare) C++., C++. DOS DOS. C++,. Corporate and Professional Publishing Division. (Kim Dawley), (Lana Langlois), (Simone Payment), (Marty Rabinowitz), (Pradeepa Siva), (John Wait)..,. C++ Report. (Kathy Reed) ( ).. (Donald French) C++.,. (Beaver Ridge)3 ( (Jayni Besaw), (Lorri Fields), (Beth McKee)).
29 L..,,.?,..., (Persephone)..,..
C++ 1). 10, C++. C++, C++??. C++, (C ). C++.,. C++,,.. C++. 1990 C++?. 1992?.? C++.. C++? ( ) 1) 1 1996, ANS I C+ +. J ava 1. 2003, C+ + PC, C/ S,, PC.
32?,,.? (more effective) C++.,,,,,,,,.?. 35. C++,. (guideline).,,. 35. C++,., 9 15 (exception)., C++., 25 31, ( ),.. 16 24..,., More Effective C++ C++. C++, C++,. C++.
33?, C++, ( ). (class), (visibility protection level),,. C++., C++. Mo re Effe c t ive C + + C + + C++ ISO/ANSI 1998.,.. (template), C++., (exception) 9 15.,. 9 15,. C++,,. ( ) ( ),.. 2), ( ). ( ),. 2) 2002,., MSVC+ +.NET gcc 2.95x, C+ + 5 (MSVC+ + 6 (exception specify), (?) ).
34 ( )? C++,.,.. (, )., C++..,., C++.,.,. bool. t r ue f al se. bool.. e n um b o o l { f a l s e, t r u e } ; bool i nt (overload), ( ==, <, >=, ) i nt.,. v o i d f (i n t ) ; v o i d f (b o ol ) ; i n t x, y ;... f ( x < y ) ; / / f (i n t ). / / f (b o o l ).
35, enum bool bool., bool typedef t r ue f al s e. t yp e d e f i n t b o o l ; c on s t b o ol f a l s e = 0 ; c on s t b o ol t r u e = 1 ; C C++. bool., bool i nt... C++ st at i c_cas t, cons t _ca st, dynami c_cas t, r ei nt er pr et _cas t., 2. C,. C++. C++.. s t r i ng C char *,. st r i ng char *,., ( 9 10 ). st r i ng char *, ( 29 ). s t r i ng s t r i ng.. char *.
36 (Standard Template Library,. STL. 35 ). STL (bitset), (vector), (list), (queue), (stack), (map), (set).,. STL. (SGI) STL. SGI STL ht t p : / / www. sgi. com/ t ech/ s t l /. 3), STL. STL, STL.? STL( ). (inheritance) public. public. -. 31. GameObject SpaceShip SpaceStation Asteroid Eff ective C++ 1 (2 ). C++,. 3), www.stlport.org STL Stlport.
37 4) (GameObj ect ), (SpaceShi p). C++ (pointer) (reference)., (declared).. Game Ob j e c t *p g o = / / p g o n e w Sp a c e Sh i p ; / / Game Ob j e c t *, / / Sp a c e Sh i p *. As t e r o i d *p a = n ew As t e r o i d ; p g o = p a ; Game Ob j e c t & r g o = *p a ; / / p a / / As t e r o i d *. / /. / / p g o / / ( ) / / Game Ob j e c t *. / / p g o / / As t e r o i d *. / / r g o / / Game Ob j e c t. / / As t e r o i d.. pgo pointer-to-gameobj ect, pa pointer-to-ast er oi d. r go reference-to-gameobj ect.. l hs r hs. left-hand side( ) right-hand side( ).. c l a s s Ra t i on a l {... } ; 4 ) diagram, UML.
38 Rat i onal ( ),. b o o l op e r a t o r == (c on s t Ra t i on a l & l h s, c on s t Ra t i on a l & r h s ) ;. Ra t i on a l r 1, r 2 ;... i f (r 1 == r 2 )... oper at or ==, r 1 == l hs, r 2 r hs.. ctor constructor( ), dtor destructor( ), RTTI RunTime Type Identification(. dynami c_cast ). 5),. C C++, C++., C++,.. c l a s s Wi d ge t {... } ; / / - / /. Wi d g e t *p w = n e w Wi d g e t ; / / Wi d g e t / /.... / / p w (d e l e t e ) / /. 5) ctrl/ dtor /.
39. pw Wi dget., Wi dget Wi dget (,,, (lock) ),. C++, (resource leak)., (inline).. C++.,,.,. More Eff ective C++,.,. C++. C++.,. C++,.,.,. (client), ( ), ( ). Dat e (, ),., Dat e..?,?,. (client centric).,.
40?.,..,, (instantiation)., T Ar r ay, ( ) Ar r ay. Ar r ay<t>., swap T, swap<t> swap.,.,,,. (,, ). (printing)... C++...,,. Scott Meyers c/o Editor-in-Chief, Corporate and Professional Publishing Addison-Wesley Publishing Company 1 Jacob Way Reading, MA 01867 U. S. A. mec++@awl. com.
41 1 (first printing).,, ( ). URL 6) ht t p :/ /www. awpr of essi onal. com/ cat al og/ pr oduct. asp?pr oduct _i d={3923c66a- 8589-44A3-8A87-926854646935}. FTP f t p. awl. com / aw.pr of. comp. ser i es.,.. ht t p : / /www. ar i st ei a. com/ Mai l i ngli st / i ndex. ht ml..?! 6) http:// www.awprofessional.com/ Scott Meyers.
,. C++,,,,? C++..,., C C++.,, C.. C++ C, C (array) C++.,, C++.,.
44 1 : (p o inte r) (re fe re nc e ) -> ( *,. ),.,.,?, (null reference)..,,,., (null).,,.,..?. c h a r *p c = 0 ; / / c h a r & r c = *p c ; / / / /., ( ).,..., (null)., C++.
45 s t r i n g & r s ; / /! / /. s t r i n g s ("x y z z y " ) ; s t r i n g & r s = s ; / /. r s s.. s t r i n g *p s ; / / / /. C++.?. v o i d p r i n t Doub l e (c on s t d oub l e & r d ) { c ou t << r d ; / / r d } / /. d oub l e., ( ). v o i d p r i n t Doub l e (c on s t d oub l e *p d ) { i f (p d ) { / /. c ou t << *p d ; } }... s t r i n g s 1 ( "Na n c y " ) ; s t r i n g s 2 ( " Cl a n c y " ) ;
46 s t r i n g & r s = s 1 ; / / r s s 1. s t r i n g *p s = &s 1 ; r s = s 2 ; p s = &s 2 ; / / p s s 1. / / r s s 1, / / s 1 / / " Cl a n c y ". / / p s s 2. / / s 1., (, ), ( )..,.. oper at or [], ( ). v e c t o r <i n t > v (1 0 ) ; v [5 ] = 10 ; / / 1 0 i n t. / / (v e c t o r ) / / ( 3 5 ). / / op e r a t o r [ ] / /. oper at or [],. *v [5 ] = 1 0 ; v.. oper at or [] (, 30 ).
47,,,..?. 2 : C+ + got o 1 (cast, ). got o..., C., C.., (const ) (, (cons t ness) ) (, ). C (. C++ C ). C.. C++?,?.,, gr ep 1). C++ C C++. st at i c_cast, const _cast, dynami c_cast, 1) Unix.
48 r ei nt er pr et _ca st,, C++ ( ). s t a t i c_ c a s t < > ( ). i nt doubl e. C. i n t f i r s t Numb e r, s e c on dnumb e r ;... d oub l e r e s u l t = ( (d oub l e ) f i r s t Numb e r ) / s e c on dnumb e r ;. d oub l e r e s u l t = s t a t i c_ c a s t <d oub l e > (f i r s t Numb e r ) / s e c ondnumb e r ;. st at i c_cast C,. C., st r uct i nt doubl e., st at i c_cast (const ness). const _cast. C++. const _cast (vol at i l eness).,, const vol at i l e.
49 const _cast..., c l a s s Wi d g e t {... } ; c l a s s Sp e c i a l Wi d g e t : p ub l i c Wi d g e t {... } ; v o i d up d a t e (Sp e c i a l Wi d g e t *p s w) ; Sp e c i a l Wi d ge t s w; / / s w. c on s t Sp e c i a l Wi d g e t & c s w = s w; / / c s w / /. up d a t e (&c s w) ; / /! c on s t Sp e c i a l Wi d ge t * / / Sp e c i a l Wi d g e t * / /. up d a t e (c on s t _ c a s t < Sp e c i a l Wi d ge t *> (&c s w) ) ; / /. &c s w / / (c s w - s w / / - up d a t e / / ). up d a t e ( (Sp e c i a l Wi d g e t * ) &c s w) ; / /. / / C. Wi d g e t *pw = n e w Sp e c i a l Wi d g e t ; up d a t e (p w) ; / /! pw Wi d g e t *, / / up d a t e Sp e c i a l Wi d g e t *. up d a t e (c on s t _ c a s t < Sp e c i a l Wi d ge t *> (pw) ) ; / /! c on s t _ c a s t / /, / / 2 ) / /. const _cast. 2), (down casting).
50 C++ dynami c_cast.., dynami c_cast (derived), (sibling) 3). ( ) ( ). Wi d g e t *p w;... up d a t e (d yn ami c_ c a s t < Sp e c i a l Wi d g e t *> (p w) ) ; / /. up d a t e p w / / Sp e c i a l Wi d ge t. / / p w, / /. v o i d up d a t evi a Re f (Sp e c i a l Wi d g e t & r s w) ; up d a t evi a Re f (d yn ami c_ c a s t < Sp e c i a l Wi d g e t &> (*p w) ) ; / /. pw / / up d a t evi a Re f *p w Sp e c i a l Wi d g e t / /. / /. dynami c_cast.. ( 24 ),. i n t f i r s t Numb e r, s e c on dnumb e r ;... d oub l e r e s u l t = d yn ami c_ c a s t <d oub l e > (f i r s t Numb e r ) / s e c on dnumb e r ; / /!. c on s t Sp e c i a l Wi d g e t s w;... up d a t e (d yn ami c_ c a s t < Sp e c i a l Wi d g e t *> (&s w) ) ; / /! d yn ami c_ c a s t / /. 3), dynamic_cast. 27.
51, st at i c_cast, const _cast. C++ r ei nt er pr et _cast..,. r ei nt erpr et _cast.,. t yp e d e f v o i d (* Fu n c Pt r ) ( ) ; / / Fu n c Pt r / / v o i d / /. Fu n c Pt r f u n c Pt r Ar r a y [1 0 ] ; / / f u n c Pt r Ar r a y 1 0 Fu n c Pt r / /. f uncpt rar r ay. i n t d o Some t h i n g ( ) ;. dosomet hi ng f uncpt r Ar r ay. void, dosomet hi ng i nt? f u n c Pt r Ar r a y [ 0 ] = &d o Some t h i n g ; / /!. r ei nt er pr et _ca st. f u n c Pt r Ar r a y [ 0 ] = / /. r e i n t e r p r e t _ c a s t < Fu n c Pt r > (&d o Some t h i n g ) ; (C++ ),
52. ( 31 ), C++?. st at i c_cast, const _cast, r ei nt erpr et _cast.,. #d e f i n e s t a t i c_ c a s t (TYPE, EXPR) ( (TYPE ) (EXPR) ) #d e f i n e c on s t _ c a s t (TYPE, EXPR) ( (TYPE ) (EXPR) ) #d e f i n e r e i n t e r p r e t _ c a s t (TYPE, EXPR) ( (TYPE ) (EXPR) ).. d oub l e r e s u l t = s t a t i c_ c a s t (d oub l e, f i r s t Numb e r ) / s e c ondnumb e r ; up d a t e (c on s t _ c a s t (Sp e c i a l Wi d g e t *, &s w) ) ; f u n c Pt r Ar r a y [ 0 ] = r e i n t e r p r e t _ c a s t (Fu n c Pt r, &d o Some t h i n g ) ;,,.,? dynami c_cast.., C.. dynami c_cast. #d e f i n e d yn ami c_ c a s t (TYPE, EXPR) ( (TYPE ) (EXPR) ), dynami c_cast..
53, 10. C++. C++ C., C++. C++ ( ),. C?.. 4) 3 :,..., (array)..,.. BST(binary search tree. ), BST Bal ancedbst. c l a s s BST {... } ; c l a s s Ba l a n c e d BST : p ub l i c BST {... } ;,.., BST Bal ancedbst i nt., BST BST. 4 ),.
54 v o i d p r i n t BSTAr r a y (o s t r e am& s, c on s t BST a r r a y [ ], i n t numel eme n t s ) { f o r (i n t i = 0 ; i < n umel eme n t s ; ++i ) { s << a r r a y [i ] ; / / op e r a t o r << } / / BST } / /. BST. BST BSTAr r a y [ 1 0 ] ;... p r i n t BSTAr r a y (c ou t, BSTAr r a y, 1 0 ) ; / /.. Bal ancedbst pr i nt BSTAr r ay? Ba l a n c e d BST b BSTAr r a y [1 0 ] ;... p r i n t BSTAr r a y (c ou t, b BSTAr r a y, 10 ) ; / /?.. f o r (i n t i = 0 ; i < n umel eme n t s ; ++i ) { s << a r r a y [i ] ; }, ar r ay [i ]., * (ar r ay+i ).. ar r ay+i. i *si zeof ( ). ar r ay [0] ar r ay [i ] i.,
55,.,. ar r ay BST, BST, ar r ay ar r ay+i i *si zeof (BST).., Bal ancedbst pr i nt BSTAr r ay., si zeof (BST ), Bal ancedbst.,., pr i nt BSTAr r ay Bal ancedbst? pr i nt BSTAr r ay Bal ancedbst.. (delete),.. / /, / /. v o i d d e l e t ear r a y (o s t r e am& l o g St r e am, BST a r r a y [ ] ) { l o g St r e am << " De l e t i n g a r r a y a t a d d r e s s " << s t a t i c_ c a s t <v o i d *> (a r r a y ) << ' \ n ' ; d e l e t e [ ] a r r a y ; } Ba l a n c e d BST *b a l Tr e ear r a y = n e w Ba l a n c e d BST [5 0 ] ; / / Ba l a n c e d BST / /.... d e l e t ear r a y (c ou t, b a l Tr e ear r a y ) ; / /.., ( 8 ).?,
56 d e l e t e [ ] a r r a y ;. / / *a r r a y, / /. f o r (i n t i = - 1 ; i >= 0 ; - - i ) { a r r a y [i ]. BST : : ~BST ( ) ; / / a r r a y [i ] } / /.,. C++,,...,.,. (BST ) (Bal ancedbst ),. 33, 33. 4 : (default constructor, ) C++.,.., ( ) 0.
57 ( 28 ) (null).,,.,.., (address book). ID, ID,.,,.,,.,., ID (Equipment) (?). c l a s s Equ i pme n t Pi e c e { p ub l i c : Equ i pme n t Pi e c e (i n t I DNumb e r ) ;... } ; Equi pment Pi ece,..,, Equi pment Pi ece. Equ i pme n t Pi e c e b e s t Pi e c e s [ 10 ] ; / /! Equ i pme n t Pi e c e / /. Equ i pme n t Pi e c e *b e s t Pi e c e s = n e w Equ i pme n t Pi e c e [1 0 ] ; / /!
58.. i n t I D1, I D2, I D3,..., I D1 0 ; / / I D / /... Equ i pme n t Pi e c e b e s t Pi e c e s [ ] = { Equ i pme n t Pi e c e (I D1 ), Equ i pme n t Pi e c e (I D2 ), Equ i pme n t Pi e c e (I D3 ),..., Equ i pme n t Pi e c e (I D1 0 ) } ; / /. / /., (new ).. t yp e d e f Equ i pme n t Pi e c e * PEP ; / / PEP p o i n t e r t o a n / / Equ i pme n t Pi e c e ". PEP b e s t Pi e c e s [ 10 ] ; PEP *b e s t Pi e c e s = n e w PEP [ 1 0 ] ; / /.. / /. Equi pment Pi ece. f o r (i n t i = 0 ; i < 1 0 ; ++i ) b e s t Pi e c e s [i ] = n ew Equ i pme n t Pi e c e (I D Numb e r ) ;.,..,. Equi pment Pi ece.
59,. (raw) new(placement new) ( 8 ) Equi pment Pi ece. / / 1 0 Equ i pme n t Pi e c e / /. op e r a t o r n e w [ ] 8 / /. v o i d * r a wmemo r y = op e r a t o r n e w [ ] (1 0* s i z e o f (Equ i pme n t Pi e c e ) ) ; / / b e s t Pi e c e s Equ i pme n t Pi e c e / /. Equ i pme n t Pi e c e *b e s t Pi e c e s = s t a t i c_ c a s t <Equ i pme n t Pi e c e *> (r a wmemo r y ) ; / / " n e w (p l a c eme n t n ew) " ( 8 ) / / Equ i pme n t Pi e c e 1 0. f o r (i n t i = 0 ; i < 10 ; ++i ) n e w (b e s t Pi e c e s +i ) Equ i pme n t Pi e c e (I D Numb e r ) ;, Equi pment Pi ece. ( ),., C++.?. new, (, )., oper at or del et e []( 8 ). / / b e s t Pi e c e s / /. f o r (i n t i = 9 ; i >= 0 ; - - i ) b e s t Pi e c e s [i ]. ~Equ i pme n t Pi e c e ( ) ;
60 / /. op e r a t o r d e l e t e [ ] (r a wmemo r y ) ;,. new (undefined). d e l e t e [ ] b e s t Pi e c e s ; / /! b e s t Pi e c e s / / n ew / /. new new, 8. (?).?, 5)., Ar r ay. t emp l a t e < c l a s s T> c l a s s Ar r a y { p ub l i c : Ar r a y (i n t s i z e ) ;... p r i v a t e : T *d a t a ; } ; t emp l a t e < c l a s s T> Ar r a y<t> : :Ar r a y (i n t s i z e ) { d a t a = n e w T [s i ze ] ; / /... / / T : : T ( ). } 5) (complex), C+ + int, double.
61,. vect or ( ),.,..,..,.?. (virtual base class).,.,.,,.?,.., Equi pment Pi ece. c l a s s Equ i pme n t Pi e c e { p ub l i c : Equ i pme n t Pi e c e (i n t I DNumb e r = UNSPECI FI ED) ;... p r i v a t e : s t a t i c c on s t i n t UNSPECI FI ED; / / I D / / } ; / /., Equi pment Pi ece. Equ i pme n t Pi e c e e ; / /
62,., Equi pment Pi ece. ID Equi pment Pi ece, ID.,. ID.,.. ( ),.,.....,.,., /.