Tải bản đầy đủ (.pdf) (7 trang)

A Complete Guide to Programming in C++ part 85 potx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (388.04 KB, 7 trang )

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


INDEX
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

INDEX
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

INDEX
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

×