P ro gra m m i n g l a n gu a ge s — C + +
L a n g a g es de p rog ra m m a tio n — C+ +
I N T E R N AT I O N A L
S TA N D A R D
I S O / I E C
1 4 8 8 2
Refere n ce n u m b e r
I S O / I E C 1 48 8 2 : 2 0 1 7 (E )
F i fth e d i ti o n
2 0 1 7 - 1 2
©
I S O / I E C 2 0 1 7
i i
© I S O / I E C 2 0 1 7 – Al l ri gh ts re s e r ve d
C O P YRI G H T P RO T E C T E D D O C U M E N T
© I S O / I E C 2 0 1 7 , Pu b l i s h e d i n S witz e r l an d
Al l ri gh ts re s e rve d . U n l e s s o the r wi s e s p e ci fi e d , n o p a rt o
f
th is p u b l i c ati o n m ay b e re p ro d u ce d o r uti l i z e d o th e r wi s e i n an y
f
o rm
o r b y an y m e a ns , e l e c tro n i c o r m e ch a n i ca l , i n c l u di n g p h o to c o p yi n g, o r p o s ti n g o n th e i nte r ne t o r an i n tra n e t, wi th o u t p r i o r
wri tte n p e r mi s s i o n . Pe r m i s s i o n c a n b e r e qu e s te d
f
ro m e i th e r I S O a t th e a dd re s s b e l o w o r I S O ’ s m e m b e r b o d y i n th e c o u n try o
f
the re q u e s te r.
I S O co p yr i gh t o
f
fi c e
C h . d e B l an d o n ne t 8 • C P 4 0 1
C H - 1 2 1 4 Ve r n i e r, G e n eva, S wi tz e rl a n d
Te l. + 4 1 2 2 7 4 9 0 1 1 1
Fax + 4 1 2 2 7 4 9 0 9 47
co p yri gh t@ i s o . o rg
www. i s o . o r g
I S O / I E C 1 4 8 8 2 : 2 0 1 7 ( E )
I S O / I E C 1 4 8 8 2 : 2 0 1 7 ( E )
C o nt e nt s
Fo r e wor d x i
1 S c o p e 1
2 No r m at i ve r efe r e n c es 2
3 Te r ms an d d e fi n i t i o n s 3
4 G e n er al p r i n c i p le s 7
4 . 1 I mp l em e nt a t i o n c o mp l i an ce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4 . 2 S t r uc t ur e o f t h is d o c u me nt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 . 3 S y nt ax n o t a t i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 . 4 Th e C
++
me m or y mo d el . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
4 . 5 T he C
++
o b j e ct mo d e l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
4 . 6 P r o gr am ex ec u t i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1
4 . 7 M ul t i - t h r ea d ed e xe c u t i o ns an d d a t a r a ce s . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 5
4 . 8 Ackn owl e dg me nt s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 0
5 L e x i c al c o nvent i on s 2 2
5 . 1 S ep a r at e t r an sl a t i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2
5 . 2 P ha s e s o f t ra ns l at i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2
5 . 3 C h ar a c t e r s e t s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 3
5 . 4 P r e p ro c e ss i n g t o ke ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 4
5 . 5 A l t e r na t i ve t o ken s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 5
5 . 6 To ke ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 5
5 . 7 C om m ent s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 6
5 . 8 H e ad e r n am es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 6
5 . 9 P re p r o c e s s i ng nu mb e r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 6
5 . 1 0 I de nt i fie r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 7
5 . 1 1 K e ywo r ds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 8
5 . 1 2 O p e r at o r s a nd p un c t u at o rs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 9
5 . 1 3 L i t e r al s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 9
6 B as i c c o nc e p t s 3 9
6 . 1 D e cl a ra t i o ns a nd d efi n it i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 9
6 . 2 O ne - d e fin it i o n r ul e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1
6 . 3 S c o p e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4
6 . 4 N ame l o o ku p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 0
6 . 5 P r og r am a nd li n ka ge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3
6 . 6 S t a rt an d t e r mi na t i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 6
6 . 7 S t o r ag e d ur a t i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 0
6 . 8 O b j e ct l ife t i me . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
6 . 9 Ty p e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 7
6 . 1 0 L va l ue s an d r va lu e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3
6 . 1 1 Al i gn me nt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4
C o nt e nt s © IS O / I EC 2 0 1 7 – A l l r i ght s r e s e rve d i ii
I S O / I E C 1 4 8 8 2 : 2 0 1 7 ( E )
7 S t an d ar d c o nve rs i o n s
8 6
7. 1 L valu e - t o - r va lu e c onve r si o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 7
7. 2 A r r ay- t o - p o i nt e r c o nver s i on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 7
7. 3 Fun c t i o n- t o - p oi nt er c o nver s i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 8
7. 4 Te mp o r ar y ma t e r i al i z at i o n c onve r s io n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 8
7. 5 Q ua li fi c at i on c onve r si o n s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 8
7. 6 I nt e gr al p r om o t i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 9
7. 7 Fl o at i ng - p o int p r om o t i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 9
7. 8 I nt e gr a l c onve rs i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 9
7. 9 F l o at i ng- p o int c onve rs i o n s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 0
7. 1 0 F l oa t i n g- i nt e gr al c onve r si o n s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 0
7. 1 1 P oi nt e r c onve r si o n s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 0
7. 1 2 P o i nt e r t o m e mb e r c o nver s i on s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 0
7. 1 3 Fun c t i o n p o int e r c o nver s i on s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1
7. 1 4 B o o le an c onve rs i o n s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1
7. 1 5 I nt e ge r c onve rs i o n r a nk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1
8 E xp r e s s i o n s 9 3
8 . 1 P r im ar y e xp r e s s i on s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 6
8 . 2 P o s t fi x e xp r es s i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 0 9
8 . 3 U na r y e xp r es s i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 0
8 . 4 Ex p li c i t t yp e c onve rs i o n ( c as t no t at i on ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 9
8 . 5 P o i nt e r - t o- me mb e r o p e ra t o r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 0
8 . 6 M u lt i p li c at i ve o p e r at o r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 1
8 . 7 Ad d i t i ve o p e ra t o r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 1
8 . 8 S h i ft o p e ra t o r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 2
8 . 9 Re l at io n al o p e r at o rs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 3
8 . 1 0 Equ al i t y o p e r at o rs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 3
8 . 1 1 B i t wi s e AN D o p e r at o r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 5
8 . 1 2 B i t w is e e xc lu s i ve O R o p e r at or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 5
8 . 1 3 B i t wi s e i nc lu s i ve O R o p e r at o r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 5
8 . 1 4 L og i ca l A N D o p e ra t o r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 5
8 . 1 5 L o gi c al O R o p er a t o r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 5
8 . 1 6 C o n di t i on al o p e r at o r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 6
8 . 1 7 T hr ow i ng a n e xc ep t i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 7
8 . 1 8 A ss i g nm e nt an d c o mp o un d a s s i gn me nt o p e ra t o r s . . . . . . . . . . . . . . . . . . . . . . . 1 3 7
8 . 1 9 C o m ma o p er a t o r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 8
8 . 2 0 C on s t a nt e xp r e ss io n s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 3 9
9 S t a t e m e nt s 1 4 4
9 . 1 L a b el e d s t at e me nt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 4 5
9 . 2 E xp r e s s io n s t at e me nt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 4 5
9 . 3 C o m p o u nd s t a t e m ent o r b l o ck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 4 5
9 . 4 S e le c t i on s t a t e me nt s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 4 5
9 . 5 I t e r at i o n s t a t e m ent s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 4 8
9 . 6 J u mp s t at e me nt s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 5 0
9 . 7 D e cl a ra t i o n s t a t e m e nt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 5 2
9 . 8 A mb ig ui t y r e s ol ut i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 5 3
C o nt e nt s © IS O / I EC 2 0 1 7 – A l l r i ght s r e s e rve d i v
I S O / I E C 1 4 8 8 2 : 2 0 1 7 ( E )
1 0 D e cl ar at i o n s
1 5 5
1 0 . 1 S p e c ifi e r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 5 7
1 0 . 2 E num er a t i o n d ec l ar at i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 7 4
1 0 . 3 N a me s p ac e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 78
1 0 . 4 T h e
as m
de c l ar at i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 9 1
1 0 . 5 L i nk ag e s p e ci fi c at i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 9 1
1 0 . 6 A t t r ib u t e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 9 4
1 1 D e c lar at o r s 2 0 1
1 1 . 1 Ty p e n ame s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 0 2
1 1 . 2 A mb ig ui t y r e s ol u t i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 0 3
1 1 . 3 M e an in g o f de c la ra t o r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 0 4
1 1 . 4 Func t i on d efi n it i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1 6
1 1 . 5 S t r u ct u re d b in d i ng d e c la ra t i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1 9
1 1 . 6 I ni t i a li z e r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 0
1 2 C l as s e s 2 3 7
1 2 . 1 C l as s n ame s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 3 9
1 2 . 2 C la s s m e mb e r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 4 1
1 2 . 3 U ni o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 5 1
1 2 . 4 L o c al c la s s d e c la ra t i o n s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 5 4
1 3 D e ri ve d c l as s e s 2 5 5
1 3 . 1 M ul t i p l e b a se c la s s e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 5 6
1 3 . 2 M e mb e r n am e l o o k up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 5 8
1 3 . 3 Vi r t u al fun c t i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 6 1
1 3 . 4 A b s t r a ct c la s s es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 6 5
1 4 M e mb e r ac c e s s c o nt r ol 2 6 7
1 4 . 1 A cc e s s s p e c i fie r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 6 8
1 4 . 2 Ac ce s s i b i li t y o f b as e c la s s es a nd b as e c la ss m e mb e r s . . . . . . . . . . . . . . . . . . . . . . 2 6 9
1 4 . 3 Fr ie n d s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 72
1 4 . 4 P r ot e c t e d m e mb e r a c ce s s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 7 5
1 4 . 5 Ac ce s s t o v ir t u al fu nc t i on s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 76
1 4 . 6 Mu l t i p l e ac c e s s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 76
1 4 . 7 N es t e d c l as s e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 76
1 5 S p e c i al m emb e r fu n ct i o n s 2 7 8
1 5 . 1 C o n s t r uc t or s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 78
1 5 . 2 Te m p o r ar y o b j ec t s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 8 1
1 5 . 3 C o nve rs i o ns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 8 3
1 5 . 4 D e s t r u ct o rs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 8 6
1 5 . 5 Fr ee s t o re . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 8 9
1 5 . 6 I ni t ia l iz at i on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 9 1
1 5 . 7 C on s t r u c t i o n an d d e s t r u ct i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 9 8
1 5 . 8 C o py i ng a nd mov i ng c la s s o b j e c t s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 0 1
1 6 O ver l o ad i n g 3 0 9
1 6 . 1 O ve rl o ad ab l e d e c l ar at i on s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 0 9
1 6 . 2 D e c l ar at i on ma t ch i ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1 1
1 6 . 3 O ve r lo ad r e so l ut i o n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1 2
C o nt e nt s © IS O / I EC 2 0 1 7 – A l l r i ght s r e s e rve d v
- 1
- 2
- 3
前往页