T
h
e
C
+
+
L
a
n
g
u
a
g
e
T
u
t
o
r
i
a
l
3
© cplusplus.com 2008. All rights reserved
Table of contents
Table of contents ...............................................................................................................................3
Introduction ......................................................................................................................................5
Instructions for use ................................................................................................................................... 5
Basics of C++ ......................................................................................................................................7
Structure of a program ............................................................................................................................. 7
Variables. Data Types. ............................................................................................................................. 11
Constants ................................................................................................................................................ 17
Operators ................................................................................................................................................ 21
Basic Input/Output .................................................................................................................................. 29
Control Structures ............................................................................................................................ 34
Control Structures ................................................................................................................................... 34
Functions (I) ............................................................................................................................................ 41
Functions (II) ........................................................................................................................................... 47
Compound data types ...................................................................................................................... 54
Arrays ...................................................................................................................................................... 54
Character Sequences .............................................................................................................................. 60
Pointers ................................................................................................................................................... 63
Dynamic Memory .................................................................................................................................... 74
Data structures........................................................................................................................................ 77
Other Data Types .................................................................................................................................... 82
Object Oriented Programming .......................................................................................................... 86
Classes (I)................................................................................................................................................. 86
Classes (II) ............................................................................................................................................... 95
Friendship and inheritance ................................................................................................................... 100
Polymorphism ....................................................................................................................................... 107
Advanced concepts ........................................................................................................................ 113
Templates.............................................................................................................................................. 113
Namespaces .......................................................................................................................................... 120
Exceptions ............................................................................................................................................. 123
Type Casting .......................................................................................................................................... 127