The opposite page shows a definition of the Coworker class, which was designed to represent human resources data for a company. The class is used as a base class for various
employees, blue-collar, white-collar, and freelancers.
To keep things simple the Coworker class has only a name as a data member. However, it could also contain the address of an employee, or the division where the
employee works.
The Coworker class does not comprise data members to represent an employee’s
salary. It makes more sense to store data like this in derived classes where the hourly
wage and number of hours worked by a blue-collar worker and the monthly salary for a
white-collar worker are also defined. The income() method is therefore not defined for
the base class and can be declared as a pure virtual method.
415 trang |
Chia sẻ: huyhoang44 | Lượt xem: 983 | Lượt tải: 0
Bạn đang xem trước 20 trang tài liệu Kĩ thuật lập trình - Chapter 19: Overloading operators, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
efix")
& ("address") * ( "indirection")
– –("postfix")
name() typeid() type()
dynamic_cast
static_cast const_cast
reinterpret_cast
new new[] delete delete[]
(type) sizeof()
OPERATOR PRECEDENCE TABLE ■ 797
■ ASCII CODE TABLE
decimal octal hex character decimal octal hex character
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
20
21
22
23
24
25
26
27
28
29
2A
2B
2C
2D
2E
2F
30
31
32
33
34
35
36
37
38
39
3A
3B
3C
3D
3E
3F
(BLANK)
!
"
#
$
%
&
'
(
)
*
+
,
-
.
/
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
040
041
042
043
044
045
046
047
050
051
052
053
054
055
056
057
060
061
062
063
064
065
066
067
070
071
072
073
074
075
076
077
000
001
002
003
004
005
006
007
010
011
012
013
014
015
016
017
020
021
022
023
024
025
026
027
030
031
032
033
034
035
036
037
00
01
02
03
04
05
06
07
08
09
A
B
C
D
E
F
10
11
12
13
14
15
16
17
18
19
1A
1B
1C
1D
1E
1F
(NUL)
(SOH)
(STX)
(ETX)
(EOT)
(ENQ)
(ACK)
(BEL)
(BS)
(HT)
(LF)
(VT)
(FF)
(CR)
(SO)
(SI)
(DLE)
(DC1)
(DC2)
(DC3)
(DC4)
(DC5)
(SYN)
(ETB)
(CAN)
(EM)
(SUB)
(ESC)
(FS)
(GS)
(RS)
(US)
798 ■ A P P E N D I X
■ ASCII CODE TABLE (CONTINUED)
decimal octal hex character decimal octal hex character
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
60
61
62
63
64
65
66
67
68
69
6A
6B
6C
6D
6E
6F
70
71
72
73
74
75
76
77
78
79
7A
7B
7C
7D
7E
7F
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
(DEL)
140
141
142
143
144
145
146
147
150
151
152
153
154
155
156
157
160
161
162
163
164
165
166
167
170
171
172
173
174
175
176
177
100
101
102
103
104
105
106
107
110
111
112
113
114
115
116
117
120
121
122
123
124
125
126
127
130
131
132
133
134
135
136
137
40
41
42
43
44
45
46
47
48
49
4A
4B
4C
4D
4E
4F
50
51
52
53
54
55
56
57
58
59
5A
5B
5C
5D
5E
5F
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_
ASCII CODE TABLE ■ 799
■ SCREEN CONTROL SEQUENCES
The following escape sequences reflect the ANSI standard for screen control. Replace
the # sign by the appropriate decimal number in all cases.
ESC[#A Cursor # lines up
ESC[#B Cursor # lines down
ESC[#C Cursor # characters right
ESC[#D Cursor # characters left
ESC[z,sH or ESC[z;sf Put cursor in line z and column s
ESC[s Save cursor position
ESC[u Load saved cursor position
ESC[#K # = 0: Delete from cursor position to line end
# = 1:Delete from start of line to cursor position
# = 2: Delete whole line
ESC[2J Clear screen
ESC[#(;#...)opm # = 0: all attributes normal
# = 1: switch double intensity on
# = 4: Underline on (monochrome screens)
# = 5: Blink on
# = 7: Inverse on
# = 3x: Foreground color
# = 4x: Background color
x = 0: black x = 4: blue
x = 1: red x = 5: magenta
x = 2: green x = 6: cyan
x = 3: yellow x = 7:white
ESC[c1;c2p Change key assignments: The key with decimal code c1 will
then return code c2.
To enable these escape sequences, you must first load an appropriate screen device
driver. To do so for Windows 9x, place the following line in your CONFIG.SYS file
DEVICE = C:\Windows\Command\Ansi.sys
Win NT and Win 2000 do not supply the ANSI screen control characters. Correspond-
ing functions based on system calls are offered for download.
800 ■ A P P E N D I X
■ LITERATURE
International Standard ISO/IEC 14882, Programming Languages—C++; published by
American National Standards Institute, New York NY, 1998.
International Standard ISO/IEC 9899:1999(E), Programming Languages—C; published by
ISO Copyright Office, Case postale 56, CH-1211, Geneva 20, 1999.
Stroustrup, Bjarne, The C++ Programming Language, Addison Wesley, 2000.
Josuttis, Nicolai, The C++ Standard Library, Addison Wesley, 1999.
LITERATURE ■ 801
This page intentionally left blank
803
Note: Italicized page locators indicate figures.
index
Symbols
&, 223, 231, 691
&&, 91
+, 50, 82, 85, 157
++, 85, 355
-, 82
--, 85, 355, 420, 755
*, 82, 233, 255, 355, 691, 755
/, 82
%, 82
->, 255, 755
=, 87
+=, 50, 87
-=, 87, 355
*=, 87, 157
/=, 87
%=, 87
==, 88, 159
!=, 88, 159
<, 88, 159
<=, 88, 159
>, 88, 159
>=, 88, 159
<<, 9, 88, 229, 429
>>, 44, 229, 429
::, 209
?:, 109
[], 691, 755
//, 91
/, 707
+-, 355
‘\n’, 51, 187
(), 691
A
Abstract classes, 565-585
concrete classes versus, 569
deriving, 569
and inhomogeneous lists, 574,
575-577
pointers and references to, 570
pure virtual methods for, 566
virtual assignment in, 572, 573
Abstraction, 245
Access methods, 274, 275
AccFile class, 656
append() method of, 650, 651
Account class, 267, 392, 393
access methods for, 274
with constructors, 266
defining, 648
methods of, 248
read-only methods in, 276
sample class, 272
Account management index file, 655
accPtr array
pointers in, 364
accSort() function, 682, 683
Accuracy, 21, 786
Adapter classes, 753
access to objects in, 761
constructors for, 757
deletion in, 765
insertion in, 759
Addition, 82, 353, 417
Addresses, array, 351
Address operator, 231, 412
Address space, hash file, 658
Algorithm library
within C++ standard library, 723
Alignment
and fill characters, 67
setting, 67
Ambiguity, 591
Ambiguous keys, 769
American National Standards Institute (ANSI),
3
Ampersand character, 223, 231, 691
Analysis, 245
AND operator, 91
Angled brackets
and header files, 47
template arguments stated in, 737
Appending
in arrays, 485
at end-of-file, 639
list elements, 465, 467
append() method, 333, 481, 485, 655
for class AccFile, 650
Applications
dynamic matrices, 694, 695
index files, 652, 653
inhomogeneous lists, 574-575
area() function
defining and calling, 176, 177
Argument pointer, 685
Arguments, 43
access to, 685
arrays as, 356
command line, 366, 367
functions without, 45
macros called with, 123
objects as, 235
objects passed as, 282
passing, 178
pointer arrays as, 683
pointers as, 235
template, 730, 731
variable number of, 684, 685, 686
argv array
in memory, 366
Arithmetic operators, 20, 412
binary, 82 83
precedence of, 84
unary, 84, 85
Arithmetic shifts, 709
Arithmetic type conversions
and precedence, 707
Arithmetic types, 20, 21
in assignments, 145
arr array
in memory, 322
Array elements, 323
addressing, 353
arrays as, 331
index for, 323
pointers interrelated with, 352
Arrays
appending/deleting in, 485
as arguments, 356
as array elements, 331
class FloatArr, 427
class representing, 426, 427
defining, 322, 323
dynamic, 461
804 ■ I N D E X
dynamic storage allocation for, 460, 461
encapsulating, 333
initializing, 324, 325
length of, 357
member, 332
multidimensional, 330, 331
name and address of, 351
parameters declared as, 357
of pointers, 364
pointers moved in, 355
and pointer variables, 351
sample program, 350, 352
as sequential containers, 751
subscript operator for, 427
Arrow operator, 255
Article class, 287, 311
copy constructor of, 310
ASCII code (American Standard Code for Informa-
tion Interchange), 17, 800
Assignment operator, 87, 253, 412
overloading, 489
Assignments, 279, 488, 489
implicit type conversions in, 145, 531
type conversions in, 145, 532, 533
virtual, 572, 573. See also Compound assignments
Associative arrays, 427
Associative container classes, 769
Associative containers, 750, 751, 768, 769
and bitsets, 751
ATM (Asynchronous Transfer Mode) cells
header of, 714, 715
representing, 714
at() method, 165, 761
auto keyword, 205
Automatic lifetime, 199
auto objects, 205
auto specifier, 204
B
back() method
and container classes vector, deque, and list, 761
Backslashes, 29
bad_cast, 553
badbit, 645
Base classes, 383, 501
accessibility of, 589
access to members in, 503, 509
calling methods in, 513
conversions in references to, 535
converting to, 530, 531
multiple indirect, 590, 591
virtual, 592, 593
with virtual destructors, 548, 549
Base class object assignment, 533
Base class pointer conversion, 535
BaseE1 class, 575
defining, 574
Base initializers, 511, 595, 597, 655
Base subobject, 505
begin() method, 755, 769
Bell Laboratories, 3
Bias, 786
Bidirectional iterators, 755
Binary arithmetic operators, 82, 83
Binary bitwise operators, 713
Binary complement, 143
Binary mode
file opened in, 638
Binary operator, 415, 417
and operands, 82
Binary search algorithm, 643
Binary trees, 187
Binding, 551
Bit coded data, 707
Bit-fields, 714
defining, 715
Bitmap container class, 774, 775
Bitmaps
raster images represented with, 774, 775
Bit masks, 710, 711
creating, 713
using, 712
Bit patterns
retaining, 143
Bits
deleting, 711
manipulating, 777
Bitsets, 774, 775, 776, 777
associative containers and, 751
declaring, 775
Bitwise AND operator, 711
Bitwise exclusive OR operator, 711
INDEX ■ 805
Bitwise operators, 412, 706, 707, 751
for bit manipulation, 777
in compound assignments, 713
for creating bit masks, 713
Bitwise OR operator, 711
Bitwise shift operators, 707, 708, 709
Blocks, building, 97
Block scope
object defined with, 199
Boolean constants, 23
Boolean operator precedence, 91
Boolean values, 17
output of, 68, 69, 71
types for, 16
bool type, 17, 23, 91
Braces
and functions without arguments, 45
and variables, 33
Brackets
and parameters for macros, 123
in syntax descriptions, 612
Branches, 125
break statement, 113
sample program containing, 112
Bresenham algorithm, 776, 777
Bubble sort algorithm, 334
Built-in types, 17
C
C
programming language, 3, 49, 51
standard library header files, 48
C++
characteristics of, 2, 3
conventions in, 31
developing/translating programs in, 6, 7
historical perspective on, 3
keywords in, 30
programming language, 3
sample program, 8, 18
standard library, 7, 9, 48, 173, 723, 751, 753, 773
calc() function, 618, 619
Calling environment, 611
Capacities, 5, 763
capital() function
defining, 182
Car class, 504
accessing members of, 506
virtual method table for, 550
Case conversion
and macros, 129
Case labels, 111
Casting, 147
Castle class, 514, 515
Cast operator, 147
catch block, 615
nested, 616, 617
syntax of, 612, 613
Catching exceptions, 614
cctype header file, 129
Cell base class
and derived classes, 574
cerr stream, 58, 59
cfloat header file, 21
Character by character string comparison, 159
Character codes, 17, 69
Character constants, 23, 25
examples for, 24
Character manipulation
standard macros for, 128
Characters, 17
output of, 68, 69
reading and writing, 75
testing, 129
types for, 16
Character set, 17
char arrays, 327
CHAR_MAX, 19
CHAR_MIN, 19
char pointers, 351
array of, 367
sample function, 364
char type, 17, 19, 25, 112
char vectors, 327
cin, 429
cin stream, 47, 49, 58, 61
Class arrays
declaring, 329
sample program, 328
Class(es), 5, 245
abstract, 565-585
adapter, 753
806 ■ I N D E X
associative container, 769
base, 501
container, 753
defining, 246, 247
derived, 501
dynamic members of, 479, 480
dynamic storage allocation for, 458
example of, 246
exception, 611
friend, 424, 425
and friend functions, 423
and global functions, 51
I/O stream, 59
iterator, 755
multiply-derived, 588, 589
naming, 247
operators for, 413. See also Abstract classes;
Adapter classes; Base classes; Derived classes;
Type conversion for classes
class keyword, 247, 257
Class member access operator, 253
Class-specific constants, 309
Class template, 723
defining, 725
for sequences, 753
clear() method, 70, 645
for deleting objects in container classes, 765
for erasing containers, 771
and maps/multimaps, 773
Client class, 303
climits header file, 19
clog stream, 58, 59
close() method, 389
Closing files, 388, 389
CLS macro, 123
cmath header file, 41
Collision resolution, 658
Collisions, 658
Colons
after labels, 113
Command line arguments, 367
sample program, 366
Comma operator, 412
syntax for, 101
Commas
for separating member initializers, 301
Comments
C++ program with, 10
examples of, 11
Comparative operators, 88, 159, 355
Comparator class, 753
compare() function, 689
Comparisons
results of, 89, 159, 355
Compiler, 7
Complex declarations, 690
operators and, 691
rules for evaluating, 691
complex header file, 48
Compound assignments, 145
bitwise operators in, 713
demonstration of, 86
operators, 87
Compound conditions, 91
Concatenation operators, 50, 157
Concrete classes
abstract classes versus, 569
Conditional expressions, 109
compilation, 790
structogram for, 108
Conditional inclusion, 126, 127
Conditional operator precedence, 109
conio.h header file, 132
Constants, 23, 25
class-specific, 309
const_iterator type, 755
const keyword, 34, 36, 64, 223
const member object declaration, 303
Const objects/methods
accessing, 276, 277
pointers to, 361
Constructor calls, 594, 595
and initialization, 595
sample program, 268
in virtual base classes, 597
Constructors, 251, 465
Account class with, 266
for adapter classes, 757
calling, 269, 299
conversion, 442, 443
copy, 279
declaring, 267
INDEX ■ 807
Constructors (continued)
default, 269, 279
defining, 266, 267
initializing, 269
with inline definitions, 273
task of, 267
of vector, list, and deque, 757. See also Destructors
Container adapters, 752
Container classes, 753, 768
deleting objects in, 765
Containers, 749-782
description of, 751
length and capacity of, 763
positioning and iterating in, 755
types of, 750, 751
Containers Library, 751, 753
Contiguous memory space, 323
continue statement, 113
Control, 28
Controlling expression, 97
ControlPoint class, 424, 425
Conversion constructors, 442, 443
Conversion functions, 443
conversion constructor versus, 445
defining, 445
“Cooked mode,” 386
Copy constructor, 279
effect of standard, 486
for FloatArr class, 486, 487
proprietary version of, 487
cos() function, 40
Counter
initializing, 99
count() method
and maps/multimaps, 773
count variable, 643
cout, 9, 30, 32
cout stream, 47, 49, 58, 61
Coworker class, 566, 567
assignment for, 572, 573
CPU registers, 205
cstdlib header file, 45
C strings
initializing, 326
specializing function template for, 732
and string class, 327
ctime() function, 167
ctype.h header file, 48
Current file position, 381
currentTime() global function, 284, 285
D
Data
abstraction, 3, 245, 501
bit coding, 707
class-specific, 305
encapsulation, 3, 245, 273
structures, 463
Data blocks
transferring, 391
Data handling
with traditional procedural programming, 5
Data members, 51, 245
and methods, 505
static, 304, 305
Date class methods, 288
Daytime class operators, 414
DayTime sample class, 280
Debuggers, 7
DEC Alpha workstations
and bit-fields, 715
Decimal constant, 23
Decimals
floating-point numbers represented as, 25
Declarations, 41
within header files, 47
Declaring sequences, 756, 757
dec manipulator, 63, 73
Decrement operator, 85
and bidirectional iterators, 755
Default arguments, 182, 183
defining, 182, 183
rules for and setting of, 735
of templates, 734, 735
default constructors, 269, 279, 299, 461
Default destructors, 271
default label, 111
Default settings, for flags, 61
#define directive, 121, 127
enum constants contrasted with, 309
working with, 124, 125
delete operator, 455, 456, 457, 459
808 ■ I N D E X
delete[] operator, 461, 483
Deleting
in arrays, 485
list elements, 465, 467
objects in container classes, 765
in sequences, 764, 765
depAcc class
read() and write() methods of, 648, 649
deque container class, 755, 765
constructors of, 757
Derived classes, 501, 505
constructing/destroying, 510, 511
defining, 502
members of, 504
standard assignment of, 573
Derived class object assignment, 533
DerivedE1 class, 575
defining, 574
Derived type, 323
Destructors, 251, 465, 483, 655
calling, 271, 549
declaring, 271
default, 271
defined, 271
with inline definitions, 273
in Matrix class, 695
sample program, 270. See also Constructors
Direct base class, 503
Direct derivation, 502
displayError() function, 365
display() function, 227
display() method, 247, 253, 509
calling, 546, 547
new version of, 508
Division, 82
Dot operators, 253
Double ended queue, 753
Double quotes
and header files, 47
string constant within, 25
double type, 21, 25
do-while loop, 97
syntax for, 103
do-while statement
structogram for, 102
Downcasting, 536, 537
safety issues in, 537, 553
draw() method
and Bitmap container class, 775
and Bresenham algorithm, 777
Dynamically allocated objects
destroying, 548, 549
Dynamic arrays, 461
Dynamic binding, 551
Dynamic casting, 537
dynamic_cast operator, 553
Dynamic casts
using, 552
Dynamic data structures, 463
Dynamic matrices, 694, 695
Dynamic members, 477-498
classes with, 480
description of, 479
objects created with, 480
of varying length, 478
Dynamic memory allocation, 453-475
for containers, 751
Dynamic storage allocation
for arrays, 460, 461
for classes, 458
E
Early binding, 551
Elementary operations, 463
Element functions
for output in fields, 66
else branch, 105, 107
Else-if chains
structogram for, 106
switch statement contrasted with, 111
Embedded keys, 769
Employee class, 570
assignment for, 572, 573
Empty lists, 465, 577
empty() method, 771
and container classes, 763
Empty statements, 99
Empty strings, 25
Encapsulation, 3, 245, 257
of arrays, 333
and static data members, 307
INDEX ■ 809
end() method, 755
and associative container classes, 769
endl manipulator, 9, 61
Enumeration
definition, 309
sample program, 308
enum keyword, 309
eof bit, 387
Equals sign
and initialization, 33
erase() method, 161, 771
for deleting objects in container classes, 765
errno.h header file, 48
Error classes
defining, 618, 619
Error condition
backing out of, 615
Error handling, 387
and exception hierarchies, 619
for new handler, 457
traditional, 608, 609
Errors
avoiding, 723
common causes of, 609
input, 73
messages, 7, 43
parity bit computation and recognition of, 713
runtime, 267
templates checked for, 727
Escape sequences, 26, 28, 29, 123
decimal values and effects, 28
Euro class, 416, 417, 418
converting constructors of, 442
converting function for, 444
explicit type conversion for, 446
expressions valid for operators in, 419
with friend functions, 422
new, 420
testing conversions of, 444
Exception classes, 611
defining, 646
standard, 620, 621
Exception class members, 619
Exception declaration, 613
Exception handlers, 612, 613
searching for, 615
Exception handling, 3, 607-635
concept behind, 611
description of, 613
for files, 646
implementing own, 647
nesting, 616-617
Exception hierarchies, 619
Exceptions, 165
catching, 614
re-throwing, 617
throwing, 611, 614, 651
exceptions() method, 647
Exception specification list, 617
exchange() template function, 727
Executable file, 7
Exit code, 9
exit() function, 389
exp() function, 40
Explicit cast constructions, 537
Explicit initialization, 329
of objects, 459
Explicit inline methods, 273
Explicit instantiation
of templates, 736, 737
syntax for, 737
Explicit type conversion, 147, 443, 536, 537
for Euro class, 446
testing, 446
explicit keyword, 447
Exponential notation, 25, 65
Expressions, 83
evaluating, 97
with reference type, 228, 229
in switch statement, 111
Extended codes, 687
External functions, 207
External static object, 203
extern storage class, 200, 201, 207
extern “c”, 795
F
failbit state flag, of ios base class, 387
fail() method, 387
false keyword, 23
Fibonacci numbers, 325
Fibonacci quotients, 325
810 ■ I N D E X
Fields
input, 71
output, 66
Field width
defining, 63
specifying, 67
File access
mode, 385
stream classes for, 382
File management
and file buffer, 381
File operations, 380, 381
Files, 381
buffers, 381
closing, 388, 389
default settings for opening, 386
determining positions in, 643
error handling when opening, 387
exception handling for, 646
extensions, 7
names, 385
opening/closing, 383, 385, 387, 638
open mode of, 386
positioning for random access, 640, 641, 642, 643.
See also Header files; Records
File scope
object defined with, 199
File state, 644, 645
File stream classes, 382, 383
functionality of, 383
in iostream library, 383
File streams, 383
definition, 385
sample program/creating, 384
Fill-characters
specifying for field, 67
fill() method, 67
Filter programs
using, 131
Filters, 131
find() method, 163
and maps/multimaps, 773
fixed manipulator, 65
Fixed point output, 65
Flags, 60
for open mode of file, 386
open mode, 387
positioning, 641
state, 645, 647
FloatArr class, 740
constructors in, 483
copy constructor for, 486, 487
data members of, 478
new declarations in, 488
new methods of, 490, 491
prototype of operator function for, 489
versions of, 479, 480, 481, 484, 485
Floating-point constants, 25
examples for, 24
Floating-point division, 413
Floating-point numbers, 17, 21, 25
formatted output of, 64
inputting, 73
Floating-point types, 20, 21
conversion of, to integral type, 145
conversion of, to larger floating-point type, 143
conversion of, to smaller type, 145
Floating-point values
types for, 16
float type, 21, 25, 331
for loops
syntax for, 99
Formatting, 61
options, 63
standard settings, 65
Formatting flags, 61
Formatting operator, 63, 67
for statement, 97
sample program, 100
structogram for, 98
Fraction class, 431
simplify() method of, 448
Fractions
calculating with, 430
Friend classes, 424, 425
declaring, 425
using, 425
Friend declaration, 423
Friend functions, 422, 423
declaring, 423
overloading operators with, 423
using, 425
INDEX ■ 811
friend keyword, 423
front() method, 761
and container classes vector, deque, and list, 761
fstream class, 383, 387
Function blocks, 175
Function call operator, 420
Function calls
defined, 43
implicit type conversions in, 147, 531
sample program, 42
Function prototype, 11, 41
example of, 40
Functions, 171-195
C++ program with, 10
calling and called, 178
conversion of, 443
declaring, 40-41, 175, 177
default arguments defined for, 182, 183
defining, 174
error checking after leaving, 608
external, 207
general form of, 174, 175
hash, 658
inline, 180, 181
libraries, 173
and macros, 125
operator, 414, 415, 416
overloading, 184, 185
and passing by value, 179
pointers to, 688, 689
pointer versions of, 358, 359
recursive, 186, 187
return value of, 176
sample, 205
scheme of, with varying arguments, 684
signatures, 185
significance of, in C++, 172
static, 207
virtual operator, 573
without arguments, 45
without return value, 45
Function templates, 723
ANSI instantiation of, 737
defining, 725
explicit instantiation of, 737
passing arguments to, 730, 731
Fundamental types, 16, 17, 18, 20
example with, 303
operators for, 82-90
G
get() function, 75
getch() function, 132, 687
getline() function, 51, 155
getline() method, 75, 391
get() method, 75, 391
getPassword() function, 203, 207
get pointer, 643
getput() function, 187
get/put pointer, 639
getTypeid() method, 651
Global arrays, 325
Global functions, 9, 51
from C++ standard library, 173
methods versus, 283
programming, 175
Global objects, 199
defining, 201
using, 201
Global operator functions, 420, 421
defining, 421
Global variables, 33, 34
goto statement, 113
Graphical user interfaces, 7, 173
H
“Has-A” relationship, 299
Hash files, 658-659
Hash function, 658
Hashing, 325
Hash key, 658
Hash tables, 641
has relationship, 501
Header files, 7, 9, 41, 249
and associative containers, 768
and macros, 125
multiple inclusions of, 126
searching for, 47
and sequences, 752
standard, 48
standard class definitions in, 47
using, 46, 47
812 ■ I N D E X
Heap, 454, 455, 769
Hexadecimal constant, 23
Hexadecimals
displaying, 63
outputting, 63
hex manipulator, 63, 73
Hot potato algorithm, 778, 779
I
Identical types, 323
Identifiers, 31
declaring, 41
read-only, 223
IEEE. See Institute of Electrical and Electronic Engi-
neers
#ifdef directive, 127
if-else statement
structogram for, 104
syntax for, 105
#ifndef directive, 127
if statements
variables defined in, 105
ifstream class, 383
Implicit conversion, 531
example for, 530
Implicit inline methods, 273
Implicit instantiation, 737
of template class, 727
Implicit type conversions, 140, 141, 441, 443
in assignments, 144
avoiding, 447
to base class type, 531
in function calls, 147
#include directive, 47
Include files, 7
include folder, 47
income() method, 567, 569
in constant, 309
Increment operator, 85
and bidirectional iterators, 755
Indefinite recursion, 509
Indentation, 11
Index entries, 643
representing, 642
IndexEntry class, 642, 643
Indexes, 165, 323, 643, 653, 655
access via, 761
for array elements, 323
and bit manipulation, 777
invalid, 165
representing, 644
Index file, 653
implementing, 654, 655
IndexFile class, 656
constructor of, 644
defined, 644, 645
insert() method of, 652, 653
IndexFileSystem class
insert() and retrieve() methods of, 654,
655
Index versions
of functions, 358, 359
Indirect base class, 503
Indirect derivation, 502
Indirection operator, 232, 233, 355
Infinite loops, 101
Inheritance, 3, 59, 499-528
data abstraction and reusability, 501
derived classes, 502
is relation, 500, 501
member access, 506-507
protected members, 514, 515
redefining members, 508, 509. See also Multiple
inheritance
Inheritance graph
building, 594, 595
InhomList class
complete, 578
defining, 576, 577
Inhomogeneous lists
application with, 574
implementing, 576
terminology for, 575
init() call, 253
Initialization, 33
and constructor calls, 595
of constructors, 269
explicit, 329
of member objects, 301
of objects, 251, 279, 455
references, 223
for virtual base classes, 596, 597
INDEX ■ 813
Initialization list, 325, 329
and arrays of pointers, 365
init() method, 247, 267
Inline functions, 125, 180, 181
definition of, 181
global, 273
and macros, 181, 183
inline keyword, 181
Inline methods, 272, 273
Input
errors, 73
fields, 71
formatted, 70
formatted, for numbers, 72
redirecting standard, 130, 131
stream classes for, 58
streams, 9
input() function, 686, 687
insertAfter() method, 577
Insertion methods
in sequences, 758
in vector, deque, and list container classes, 759
Insertion sort algorithm, 738
insert() method, 161, 485, 771
of class IndexFile, 652, 653
of class IndexFileSystem, 654, 655
and maps/multimaps, 773
of SortVec derived container class, 758
Instances, class, 51, 251
Instantiation
and template definition, 723
of template functions, 733
of templates, 726, 727
Institute of Electrical and Electronic Engineers, 20
Integer promotions, 140, 141
Integers, 17
computing parity of, 712
formatted output of, 62
inputting, 73
types for, 16
Integer types, 21
Integral constants, 23
examples for, 22
Integral numbers
displaying, 63
Integral promotion, 709
Integral types, 18, 19
conversion of, to floating-point type, 143
conversion of, to smaller type, 145
and operands for bitwise operators, 707
Integrated software development environment, 7
internal manipulator, 67
Internal static object, 203
International Organization for Standardization, 3
Interpolation search, 738
INT_MAX, 19
INT_MIN, 19
int type, 19, 23
Invalid indexes, 427
invalid_argument class, 620
I/O (input/output)
formatted/unformatted, 74, 75, 391
overloading shift operators for, 428
redirecting, 130, 131
iomanip header file, 48, 65, 66
ios baseclass
flags defined in, 386
ios::boolalpha flag, 69
ios class, 59
ios::seekdir type positioning flags, 641
iostream class, 59
iostream header file, 9
iostream library, 59
file stream classes in, 383
isLess() method, 282
islower(c) macro, 129
ISO. See International Organization for Standardiza-
tion
is_open() method, 389
is relationship, 500, 535, 589
istream class, 47, 59, 61
Iterating lists, 754
Iterator classes, 755
Iterators, 754
types of, 755
J
Jump table, 688, 689
K
kbhit() function, 132
814 ■ I N D E X
Keys
and adapter classes, 753
and associative containers, 751
hash, 658
representing pairs of, 773
and sets and multisets, 771
unique and ambiguous, 769
Keyword, 29
L
Labels
and goto statement, 113
Laborer class, 568
standard assignment for, 573
Layout
and program flow, 107
of source files, 11
Left shift operators, 708, 709
left manipulator, 66
Legibility, 11
Length, of container, 763
length_error(*) class, 620
length() method, 51, 481
Less-than symbols, 9
Libraries
functions in, 173
Lifetime
object, 199
static, 203
LIFO (last-in-first-out) principle, 179, 725, 751
Lights class, 309
limits header file, 48
Linear solution, 658
Line feed, 187
line() function, 11
Linked lists, 462, 463
advantages with, 463
defining, 463
representing, 464
Linker, 7
List class
class definition for, 464, 465
new methods of, 490, 491
list container class, 767
constructors of, 757
methods for deleting objects in, 765
List elements
appending/deleting, 462, 465, 467
inserting in middle of inhomogeneous list, 576
inserting new, 577
representing, 465, 575
List operations sample program, 766
Lists
representing, 465
sorting, inverting, and splicing, 767
Literals, 23
Local objects, 179, 199
Local variables, 33, 34
LOCATE macro, 123
Logarithmic runtimes, 769
Logical bitwise operators, 707
Logical expressions
examples for, 90
Logical operators, 90, 141, 412
Logical shifts, 709
logic_error
exception classes derived from, 620, 621
long double type, 21, 25
long type, 19
Loop body, 97
Loops, 97
l-value, 233, 421
M
Macro definition
visibility for, 125
Macros
calling with arguments, 123
and case conversion, 129
for character manipulation/classification, 128
defining, 121
in different source files, 124
within header files, 47
and inline functions, 181, 183
redefining, 127
sample program, 120
for screen control, 123, 125
Macros with parameters sample program, 122
main() function, 9, 11, 173, 175
parameters of, 367
structure of, 8
MAKE utility, for module management, 173
INDEX ■ 815
Manipulators, 61
calling, 60
floating-point numbers formatting, 64
and integers formatting, 62
for output in fields, 66
Maps
and associative containers, 751
representing, 769
using, 773
Masks, bit, 710, 711
Mathematical rules
and expressions, 83
Mathematical standard functions, 40
MathError exception class, 619
math.h header file, 190
Matrix, 331
Matrix class, 695
constructor, destructor, and subscript operator for,
695
Member arrays, 332
Member functions, 9, 51, 245
Member initializers, 300, 301
Member objects, 298, 299
constant, 302, 303
initializing, 301
Members, 247
redefining, 508, 509
Member sub-object, 299
Memory
allocating, 249
objects in, 251
releasing, 459
union and usage of, 259
Memory address
for object of class, 255
merge() method
for merging list containers, 767
of SortVec container class, 762
message() function, 227
Methods, 51, 245
calling, 51
of class template, 725
const and non-const versions of, 277, 279
and data members, 505
defining, 248, 249
global functions versus, 283
name lookup for, 507
operator functions as, 415
operators overloadable by, 420
positioning, 643
pure virtual, 566, 567
standard, 278, 279
min() function template, 732
MIN macro, 127
Modifiers
signed and unsigned, 19
Modular programming, 7, 249
Modules, 7, 173, 199
MotorHome multiply-derived class, 588, 589, 598
move() method
and BitmapN container class, 775
Multidimensional arrays
defining, 331
as parameters, 359
sample program, 330
Multimaps, 769
using, 772, 773
Multiple assignments, 87
Multiple indirect base classes, 590, 591
Multiple inheritance, 587-606
constructor calls, 594
initializing virtual base classes, 596
multiple identical base classes, 591
multiple indirect base classes, 590
multiply-derived classes, 588, 589
virtual base classes, 592
Multiple template parameters, 729
Multiply-derived classes, 588, 589
multiset container class, 771
Multisets, 769
declaring, 771
sample, 770
N
Names and naming
arrays, 351
bit-fields, 715
constructors, 267
declaring, 41
file, 385
macros, 121
operator functions, 415
816 ■ I N D E X
source file, 7
valid, 31
of variables, 31
namespace keyword, 209
Namespaces
defining, 208, 209
n-dimensional array, 331
Negation, 417
Negative numbers
converting, 142
outputting as decimals, 63
Nested if-else statements, 105
Nested namespaces, 209
Nesting exception handling, 616, 617
Nesting loops, 103
new handler, 457
New-line characters, 11, 51
new operator, 454
calling for fundamental types, 455
calling with default constructor, 459
new[] operator, 461
noboolalpha manipulator, 69
Nongraphic characters, 28
noshowpoint(*), 64
noshowpos(*) manipulator, 60
NOT operator, 91
nouppercase manipulator, 63
NULL, 365, 465, 577
Null character, 25, 26, 327
NULL pointer, 333, 363, 457
Numbers
formatted input of, 72
Number symbol (#), 9, 11
Numerical constants, 23
Numeric operations
exception handling for, 618, 619
numeric_limits, 786
O
Object-oriented programming, 3, 4, 5, 245
Object persistence, 392, 393
Objects, 5, 33
accessing, 281, 760, 761
as arguments, 235
assigning, 253
cleaning up, 271
creating/destroying, 51, 482, 483, 511
creating with dynamic members, 480
declaring, 513
defining, 250, 251
of derived classes, 512
explicit initialization of, 459
initializing, 251, 455
lifetime of, 199
local, 179
member, 298
in memory, 251
passing as arguments, 282
passing by reference, 283
passing by value, 283
pointers to, 254, 255
references returned to, 285
representing pairs of, 773
returning, 284, 285
static, 203
storage classes of, 198
storing, 393
of union WordByte in memory, 258
using, 252. See also Classes; References
Obligatory arguments, 685
Octal constant, 23
Octal numbers
outputting, 63
oct manipulator, 63, 73
OFF constant, 309
ofstream class, 383
ON constant, 309
OOP. See Object-oriented programming
open() method, 386, 387
Open mode flags, 387
Open modes, of file, 386
Operands
and order of evaluation, 91
symmetry of, 419
Operations
file, 380, 381
for sequences, 752
Operator functions, 414, 415, 416
calling, 415, 419
declaration of, 428
defining global, 421
definition of, 428
INDEX ■ 817
Operator functions (continued)
global or method, 421
as methods, 415
naming, 415
negation, addition, and subtraction, 417
operator keyword, 415, 445
Operators
bitwise, 706, 707
for classes, 413
and complex declarations, 691
dot, 253
indirection, 232
overloadable, 412
overloading, 413
with pointer variables, 355
reference type, 229
in template functions, 733
unary, 233
Operators for fundamental types
binary arithmetic operators, 82-83
increment/decrement operators, 85
logical operators, 90
relational operators, 88, 89
sign operators, 85
unary arithmetic operators, 84
Optional arguments, 685, 687
OR operator, 91
ostream class, 47, 59, 61
out constant, 309
out_of_range(*), 620
Output
redirecting standard, 130, 131
stream classes for, 58
streams, 9
overflow_error(*) class, 620
Overloaded operators
rules for, 412
using, 418, 419
Overloading
assignment operator, 489
functions, 184, 185
operators, 413, 423
and redefinition, 509
shift operators for I/O, 428, 429
subscript operators, 426, 427, 485
P
Parameters, 175
declaring, 357
multidimensional arrays as, 359
pointers as, 234
read-only pointers as, 361
Parentheses
in syntax description, 33
Parity bit computation, 713
parity() function, 713
PassCar
versions of, 510, 511
PassCar class
virtual method table for, 550
PassCar derived class, 504
Passing arguments
to function templates, 730, 731
Passing by reference, 179, 225, 283
Passing by value, 179, 225, 283
Persistence
object, 392, 393
of polymorphic objects, 648, 650
Pixels (picture element), 775
Pointer arithmetic, 354, 355
Pointer arrays
generating dynamically, 683
Pointer assignment
effect of, 534
Pointers, 233, 285, 729, 755
to abstract classes, 570, 571
as arguments, 235
array elements interrelated with, 352
arrays of, 364
comparing, 355
to const objects, 361
defining, 230
defining arrays of, 365
to functions, 688, 689
moving in array, 355
NULL, 333
to objects, 254, 255
as parameters, 234
parameters declared as, 357
read-only, 360
returning, 362, 363
818 ■ I N D E X
sample program, 350, 352
subtracting, 355
typeless, 351
use of, instead of indices, 359
Pointers to pointers, 682, 683
Pointer types, 231
Pointer variables, 231, 235, 683
addressing with, 353
and arrays, 351
Polymorphic interfaces, 571
Polymorphic objects
persistence of, 648, 650
storing, 649
Polymorphism, 3, 543-564
concept of, 544, 545
destroying dynamically allocated objects, 548, 549
dynamic casts, 552, 553
virtual methods, 546, 547
virtual method table, 550, 551
pop_back() method
for deleting objects in container classes, 765
popFront() method, 465, 467
pop() method, 765
Positioning flags, 641
Positioning methods, 643
Positive numbers
converting to, 142
Postfix increment, 430
Postfix notation, 85
effects of, 84
Precedence
of arithmetic operators, 84
and arithmetic type conversions, 707
of Boolean operators, 91
for cast operator (type), 147
for comma operator, 101
for indirection operator, 233
operator, 85
for operators with pointer variables, 355
of relational operators, 88, 89
precision() method, 65
Prefixes, 31
Prefix increment, 430
Prefix notation, 85
effects of, 84
Preprocessor, 9
Preprocessor directives, 11
Primary file, within index file, 653, 655
printf() function, 685
Priority queues, 753
testing, 764
priority_queue template, 753
Private data members
accessing, 275
Private members, 245, 247, 249, 503, 507
Procedures, 5
Program scope
object defined with, 199
Projects, 249
Properties, 5
protected constructors, 569
Protected declarations, 515
Protected members, 515
Prototype, 175, 177
public base classes
is relationship established by, 589
Public interface, of class, 247
Public members, 245, 247
access to, in base class, 503
Public methods, 51
Pure virtual methods, 566, 567
pushBack() method, 465, 467
push_back() method, 759
push_front() method, 759
push() method, 759
put() method, 75, 391
Q
qsort() function, 689, 696, 697
QuadMatrix template, 734, 735
Quadratic matrices
class template representing, 734, 735
Queues
as sequential containers, 751
Quick sort algorithm, 187, 689
Quotient
of Fibonacci number, 325
R
rand(), 45
INDEX ■ 819
Random access iterators, 755
Random file access, 381, 639
positioning for, 640, 641, 642, 643
Random number generator
initializing, 44, 45
Random positioning statements, 643
Random read and write access, 639
Range checking, 427
Range operator, 305
base class method accessed by, 509
range_error class, 620
Raster images
representing with bitmaps, 774, 775
rdstate() method, 645
Readability
and complex expressions, 109
and empty statements, 99
and loop body, 97
and macros, 121
and typedef, 693
Read access
open mode for, 638
read_at() method, 642
Reading
blocks of records, 390
characters, 75
records, 381
read() method
of classes DepAcc and SavAcc, 648, 649
implementing, 392, 393
Read-only methods, 277
Read-only pointers, 360
for non-constant objects, 361
Read-only references, 223, 225
Records, 257
inserting and retrieving, 655
position of, in files, 643
reading, 381
reading/writing blocks, 390
Recursive data structures, 465
Recursive functions, 186, 187
Redefined methods
calling, 513
Redefinition, 509
References, 3, 729
to abstract classes, 570, 571
conversions in, to base classes, 535
defining, 222
as parameters, 224
and pointers, 231
read-only, 223, 225
returning, 285
as return value, 226, 227
sample program, 222
Reference type function
calling, 227
register keyword, 205
Registers
CPU, 205
Register variables, 205
sample function with, 204
Relational operators, 50, 412
precedence of, 88, 89
remove() method, 481, 485
replace() method, 163
reset() method
and manipulating bits, 777
Resistant mistakes
program with, 76
resize() method
and container classes, 763
Result class, 303, 424, 425
constructors for, 298, 299
new version of, 302
with static members, 304
with static methods, 306
retrieve() method, 651
of IndexFileSystem class, 654, 655
Return address, 181
return statement, 9, 177
Return values, 41, 285
Reusability, 5, 501
reverse() function, 357
reverse() method, 767
rfind() method, 163
Right shift operators, 708, 709
Round brackets, 33
Routers, 779
820 ■ I N D E X
Row class
defining, 694, 695
RTTI. See Run Time Type Information
Runtime behavior
of container classes, 759
runtime_error, 621
Run time errors, 621
avoiding, 43, 267
exception classes derived from, 620, 621
Run Time Type Information, 552
R-values, 233
S
Safe class, 514, 515
SavAcc class
defining, 648, 649
scientific manipulator, 65
Scope, 199
Scope resolution operator, 209, 211, 249
Screen control macros, 123, 125
Scrolling string output, 334
search() method, 655
seekg() method, 641
seekp() method, 641
SelectionSort() function, 697
Semicolon, 9, 103
Sequences
and header files, 752
operations for, 752
representing, 753
Sequential containers (or sequences), 750, 751
Sequential file access, 381
set container class, 771
setfill() manipulator, 66
setfill() method, 67
setf() method, 60, 61, 69
set() method, 777
setprecision() manipulator, 65
Sets
associative containers within, 751
declaring, 771
representing, 769
sample, 770
setTime() method, 282
setw() manipulator, 66
Shape type, 309
Sheltered members
access to, 515
Shift operators, 708
short type, 19
showpos manipulator
calling, 60
Side effects
avoiding, 87
of macros, 125
Sieve of Eratosthenes, 334
signal.h header file, 48
Signatures
constructor, 267, 269
function, 185
signed char type, 19, 142
Signed integers
converting, 142
signed keyword, 19
Signed type
conversion of, to larger integral type, 143
Sign extension, 143
Sign operators, 85
Simple assignments, 87
Single characters
meaning of, 26
Single quotes
character constants within, 25
size() method
and length of container, 763
and maps/multimaps, 773
and number of objects in container, 771
sizeof operator, 21
sort() method
list container sorted by call to, 767
SortVec container class
merge() method of, 762
search() method of, 760
using, 756
Source code, 7
Source files, 7, 249
layout of, 11
name, 7
INDEX ■ 821
Spaces, 11
Special characters, 28
Special objects, of base class, 531
splice() function, 466, 467
Splice operations, 767
sqrt() function, 40, 53
srand() function, 45
sstream class, 48
Stack class template, 724
explicit instantiation for, 737
with two template parameters, 728
Stack content
after calling function, 178
Stacks, 179
fixed/varying arguments on, 684
and recursive functions, 187
as sequential containers, 751
testing, 726
Standard copy constructor, 487
Standard exception classes
hierarchy of, 621
using, 620
Standard exception handling
for streams, 647
Standard input, 59
Standard methods, 279
sample program, 278
Standard output, 59
Standard settings, 65
Star character, 233
State flags, 645, 647
Statements, 9
Static arrays, 325
Static binding, 551
Static data members, 304, 305
accessing, 306
declaring, 305
definition and initialization, 305
and encapsulation, 307
Static data structures, 463
Static functions, 207
static keyword, 305
static_cast, 537
Static lifetime, 199, 203
Static member functions, 307
Static objects, 203
static storage class, 202, 203, 207
std standard namespace, 9, 209
Storage classes, 199
of functions, 206
Storage class specifiers, 198
strcat() function
and return pointers, 363
strcmp() function, 327
index version of, 368
strcpy() function, 327
pointer versions of, 358
and return pointers, 363
Stream access errors, 651
Stream class
shift operators, 229
streambuf class, 48
Streams, 9
discovering/changing status of, 645
standard, 59
standard exception handling for, 647
String assignments, 155, 157
string class, 153, 251, 413
C strings and, 327
defining, 155
objects of, 51
sample assignments of, 228
sample program, 50, 154
String constants, 23, 25
String literal
internal representation of, 24
Strings
characters accessed in, 164
comparing, 158
concatenating, 156, 157
escape sequences used in, 29
initializing, 154, 155
inserting and erasing in, 160, 161
numbers converted to, 288
output of, 68, 69
searching and replacing in, 162, 163
stringstream class, 288
strlen() function, 327, 359
Stroustrup, Bjarne, 3
strstr() function sample program, 362, 363
struct keyword, 257
structs sample program, 256
822 ■ I N D E X
Style, 11
Sub-object lattice, 595
Subroutines, 5, 181
Subscript, 323
Subscript operators, 165, 427
and access via indices, 761
bits referenced by, 777
in Matrix class, 695
overloading, 426, 427
read and write access using, 485
Substrings
erasing, 160
replacing, 162
Subtraction, 355, 417
swap()
implementing as method, 282
swap() function, 235
Swapping, 455
switch statement, 111
else-if chains contrasted with, 111
structogram for, 110
Symbolic constants, 121
sync() method, 70
Syntax, 249
brackets in descriptions, 612
for defining variables, 33
errors, 7
T
Tabs, 11
tan() function, 40
tellg() method, 641
TelList class, 332, 333
methods implemented for, 336, 337
tellp() method, 641
Template arguments
restrictions on, 731
Template function definition, 733
Template functions
motivation for, 733
Template parameters
multiple, 729
restrictions on, 729
Templates, 3, 721-748
advantages of, 723
arguments, 730, 731
in C++ standard library, 723
default arguments of, 734, 735
defining, 724, 725
defining with multiple parameters, 729
function and class, 723
instantiating, 726, 727, 736, 737
parameters, 728, 729
specialization, 732-733
terminate() function, 613
Testing characters, 129
Text
mode, 386
and nesting loops, 103
Text editor, 7
this pointer
sample class DayTime, 280
using, 281
Throwing exceptions, 614
throw statement, 611
using, 610
timediff() function, 207
time() function, 167
time_t type, 261
tm struct, 260
Tokens, 11
Tone
and nesting loops, 103
top() method, 761
toupper() macro, 129
Traditional procedural programming, 4, 5
Translation unit, 199
true keyword, 23
trunc open mode, 386
Truth table
for logical operators, 90
try block, 615
nested, 616, 617
syntax of, 612, 613
Two-dimensional arrays
initialization list of, 331
parameter declaration for, 359
Type casting, 351
Type conversion for classes, 441-452
ambiguities of type conversions, 446-447
conversion constructors, 442-443
conversion functions, 444-445
INDEX ■ 823
Type conversions, 43, 146
ambiguities of, 446, 447
in assignments, 145, 532, 533
explicit, 147, 536, 537
failure, 447
implicit, 140, 144, 147, 531
standard, 445
usual arithmetic, 141, 142
typedef keyword, 693
Type hierarchy, 140
Typeless pointers, 351
Typenames
defining, 692
Types, 611
platform dependent, 693
pointer, 231
U
Unary arithmetic operators, 84, 85
Unary operators, 83, 233
underflow_error class, 620
#undef directive, 127
Underscores
and internal names, 31
Unicode, 17
Union, 258, 259
defined, 259
Unique keys, 769
usetf() method, 60, 61
unsigned char type, 19
unsigned keyword, 19
unsigned short, 19
Unsigned types, 143
Unsigned value, 45
Unwinding the stack, 615
Upcasting, 536, 537, 553
User Network Interface, 715
using declaration, 211
using directive, 211
using keyword, 9, 49, 210
Usual arithmetic type conversions, 141, 145
performing, 142
V
va_arg() macro
arguments of, 687
valarray class, 48
Variables
defining, 33
defining in if statements, 105
names of, 31
pointer, 683
sample program, 32
Variable type, 77
Vector, 323
vector container class, 755
constructors of, 757
methods for deleting objects in, 765
Vectors
iterating, 754
Virtual assignments
using, 573
Virtual base classes, 592, 593
constructor calls in, 597
initializing, 596, 597
Virtual destructors
declaring, 549
virtual keyword, 593
Virtual methods, 546, 547
calling, 544, 545
declaring, 547
pure, 566, 567
redefining, 547
Virtual method tables, 550, 551
Virtual operator functions, 573
VMT. See Virtual method tables
void type, 21
for functions, 44, 45
void* type pointer, 351
volatile keyword, 34, 36
W
Warnings, 7
wchar_t type, 17, 19
what() method, 621
824 ■ I N D E X
what() virtual method, 647
while statement
structogram for, 96
structogram for break within, 112
syntax for, 97
Whitespace characters, 11
Width
bit-fields, 715
width() method, 67, 491
Wordbyte union
defining/using, 258
Write access
open mode for, 638
write_at() method, 642
WriteError type exception, 651
write() method, 391, 392, 393
of classes DepAcc and SavAcc, 648, 649
Write operation, 381
Writing
blocks of records, 390
characters, 75
X
XOR operator, 707
Z
Zero extension, 143
INDEX ■ 825
Các file đính kèm theo tài liệu này:
- c_2_4576.pdf