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_queuetemplate, 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
publicbase 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
QuadMatrixtemplate, 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
Trang 2Random 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_errorclass, 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
andtypedef, 693
Read access
open mode for, 638
read_at()method, 642
Reading
blocks of records, 390
characters, 75
records, 381
read()method
of classes DepAccandSavAcc, 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
registerkeyword, 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
Resultclass, 303, 424, 425 constructors for, 298, 299 new version of, 302 with static members, 304 with static methods, 306
retrieve()method, 651
ofIndexFileSystemclass, 654, 655
Return address, 181
returnstatement, 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
Trang 3defining, 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
Safeclass, 514, 515
SavAccclass
defining, 648, 649
scientificmanipulator, 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
setcontainer 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
shorttype, 19
showposmanipulator
calling, 60
Side effects avoiding, 87
of macros, 125
Sieve of Eratosthenes, 334
signal.hheader file, 48 Signatures
constructor, 267, 269 function, 185
signed chartype, 19, 142 Signed integers
converting, 142
signedkeyword, 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
sizeofoperator, 21
sort()method list container sorted by call to, 767
SortVeccontainer class
merge()method of, 762
search()method of, 760 using, 756
Source code, 7 Source files, 7, 249 layout of, 11 name, 7
Trang 4Spaces, 11
Special characters, 28
Special objects, of base class, 531
splice()function, 466, 467
Splice operations, 767
sqrt()function, 40, 53
srand()function, 45
sstreamclass, 48
Stackclass 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
statickeyword, 305
static_cast, 537
Static lifetime, 199, 203
Static member functions, 307
Static objects, 203
staticstorage class, 202, 203, 207
stdstandard 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
streambufclass, 48 Streams, 9
discovering/changing status of, 645 standard, 59
standard exception handling for, 647 String assignments, 155, 157
stringclass, 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
stringstreamclass, 288
strlen()function, 327, 359 Stroustrup, Bjarne, 3
strstr()function sample program, 362, 363
structkeyword, 257
structs sample program, 256
Trang 5Style, 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
switchstatement, 111
else-ifchains 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
TelListclass, 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
thispointer sample class DayTime, 280
using, 281
Throwing exceptions, 614
throwstatement, 611
using, 610
timediff()function, 207
time()function, 167
time_ttype, 261
tmstruct, 260 Tokens, 11 Tone and nesting loops, 103
top()method, 761
toupper()macro, 129
Traditional procedural programming, 4, 5
Translation unit, 199
truekeyword, 23
truncopen mode, 386 Truth table
for logical operators, 90
tryblock, 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
Trang 6Type 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
typedefkeyword, 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_errorclass, 620
#undefdirective, 127
Underscores
and internal names, 31
Unicode, 17
Union, 258, 259
defined, 259
Unique keys, 769
usetf()method, 60, 61
unsigned chartype, 19
unsignedkeyword, 19
unsigned short, 19
Unsigned types, 143
Unsigned value, 45
Unwinding the stack, 615
Upcasting, 536, 537, 553
User Network Interface, 715
usingdeclaration, 211
usingdirective, 211
usingkeyword, 9, 49, 210
Usual arithmetic type conversions, 141, 145
performing, 142
V
va_arg()macro arguments of, 687
valarrayclass, 48 Variables
defining, 33 defining in if statements, 105 names of, 31
pointer, 683
sample program, 32
Variable type, 77 Vector, 323
vectorcontainer 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
virtualkeyword, 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
voidtype, 21
for functions, 44, 45
void*type pointer, 351
volatilekeyword, 34, 36
W
Warnings, 7
wchar_ttype, 17, 19
what()method, 621
Trang 7what()virtual method, 647
whilestatement
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
WriteErrortype exception, 651
write()method, 391, 392, 393
of classes DepAccandSavAcc, 648, 649
Write operation, 381 Writing
blocks of records, 390
characters, 75
X
XORoperator, 707
Z
Zero extension, 143