Index

Symbols

+ (addition operator), 506–510

= (assignment operator), 45, 577, 687, 691–693

compared to equality operator, 199–201

custom definitions, 578–579

enumerator values, setting, 142–143

overloading, 584–590

sayings1.cpp, 588–589

string1.cpp, 586–588

string1.h, 585

potential problems, 578

strings, 126–127

structures, 136–137

when to use, 577

*= (assignment operator), 193

+= (assignment operator), 193

/= (assignment operator), 193

-= (assignment operator), 193

%= (assignment operator), 193

& (bitwise AND operator), 1067

~ (bitwise negation operator), 1065

| (bitwise OR operator), 1065–1066

^ (bitwise XOR operator), 1066

{} (braces), 235

[] (brackets), 582–583

, (comma operator), 195–198

/*...*/ comment notation, 35

// comment notation, 29, 34–35

+ (concatenation operator), 126–127

?: (conditional operator), 250–251

— (decrement operator), 189–192

* (dereferencing operator), 145–149, 160

/ (division operator), 97–98

== (equality operator), 198–201

>= (greater than or equal to operator), 198

> (greater than operator), 198

++ (increment operator), 178, 189–192

!= (inequality operator), 198

<< (insertion operator)

concatenation, 960–961

data types recognized, 958–959

pointers, 960

<<= (left shift and assign operator), 1064

<< (left shift operator), 518–524, 606, 1063–1064

< (less than operator), 198

<= (less than or equal to operator), 198

&& (logical AND operator), 239

alternative representations, 247

example, 240–242

precedence, 246–247

ranges, 242–244

! (logical NOT operator), 244–245

alternative representations, 247

precedence, 246

|| (logical OR operator), 238–239, 246–247

->* (member dereferencing operator), 1070–1073

.* (member dereferencing operator), 1070–1073

% (modulus operator), 99–100

* (multiplication operator), 512–515

. (period), 232

# (pound sign), 214

” (quotation marks), 38

& (reference operator), 341–344

>>= (right shift and assign operator), 1065

>> (right shift operator), 1064–1065

:: (scope resolution operator), 409, 453, 1138

; (semicolon), 32

- (subtraction operator), 512–515

~ (tilde), 468

_ (underscore), 1049

A

ABCs (abstract base classes), 670–672

ABC philosophy, 677

AcctABC example, 672–676

enforcing interface rules with, 677

abort() function, 805–807, 835–836

abstract base classes. See ABCs

abstract data types (ADTs), 489–494

abstraction, 447

access control (classes), 451–453, 801

AcctABC class, 672–676

acctabc.cpp, 674–676

acctabc.h, 673–674

accumulate() function, 1127

acquire() function, 456

actual arguments, 287

adaptable binary functions, 929–930

adaptable binary predicate, 929–930

adaptable functors, 928

adaptable generators, 929–930

adaptable predicate, 929–930

adaptable unary functions, 929–930

adapters, 900

adding vectors, 526

addition operator (+), 506–510

addpntrs.cpp, 156

address.cpp, 144

addresses

addresses of functions, obtaining, 328

structure addresses, passing, 320–322

adjacent_difference() function, 1128

adjacent_find() function, 1103–1105

ADTs (abstract data types), 489–494

algorithms, 930–931

copying, 932

groups, 931

in-place, 932

properties, 932–933

aliases

creating, 210–211

namespaces, 432

allocating memory

bad_alloc exceptions, 827–829

dynamic memory allocation

auto_ptr class, 873–877

derived class does use new, 679–680

derived class doesn’t use new, 677–678

example, 681–685

new operator, 150–152

alternative tokens, 1048

American National Standards Institute (ANSI), 18, 952

American Standard Code for Information Interchange (ASCII) character set, 1051–1056

ampersand (&), 1067

logical AND operator (&&), 239

alternative representations, 247

example, 240–242

precedence, 246–247

ranges, 242–244

reference operator (&), 341–344

AND operators

bitwise AND (&), 1067

logical AND (&&), 239

alternative representations, 247

example, 240–242

precedence, 246–247

ranges, 242–244

and.cpp, 240–241

anonymous unions, 140–141

ANSI (American National Standards Institute), 18, 952

append() function, 1089

append.cpp, 1014

appending

data to files, 1014–1016

strings, 126–127, 1089–1090

applications. See also code listings

compatibility, 30

creating, 19–20

myfirst.cpp example, 29–31

comments, 34–35

header filenames, 36–37

iostream file, 35–36

main() function, 31–34

namespaces, 37–38

output, displaying with cout, 39–41

source code formatting, 41–42

portability, 17–19

source code, 20–21

apply() function, 941

Area() function, 671

arguments, 51, 54–55

argument lists, 33

arrays, 295–297

C-style strings, 310–311

command-line, 1008–1009

default arguments, 362–365

formal/actual, 287

multiple

n_chars() example, 288–290

probability() example, 291–292

parameters, 287

passing by reference, 344–347

passing by value, 286–287

reference arguments, 349–351, 361–362

two-dimensional arrays, 308–309

type conversions, 103

arith.cpp, 95

arithmetic operators, 95–96

associativity, 96–97

division, 97–98

functor equivalents, 927–928

modulus, 99–100

order of precedence, 96–97

overloading

addition operator, 506–510

multiplication operator, 512–515, 536

subtraction operator, 512–515

vector class, 535–536

pointers, 156–161

array notation, 161

ArrayDb class, 706

arraynew.cpp, 155

arrayone.cpp, 111

arrays

array notation, 161

arrays of objects

declaring, 483

example, 484–486

initializing, 483

const keyword, 299–300

declaring, 110–113

defined, 110

design decisions, 297–298

displaying contents of, 299–300

dynamic arrays, 161

creating, 153–155

sample program, 155–156

examples, 300–303

external arrays, 243

filling, 298–299

as function arguments, 293–297

indexes, 110–111

initializing, 111–114

modifying, 300

naming, 160

one-dimensional arrays, 223

pointer arithmetic, 156–161

pointers, 294–295

ranges, 303–304

static binding, 161

strings, 114–117

structures, 137–139

subscripts, 111

templates, 756–758

two-dimensional arrays, 223–227, 308–309

declaring, 224–225

initializing, 225–227

variable arrays, 1135

arraytp.h, 756–757

arrfun1.cpp, 293

arrfun2.cpp, 296

arrfun3.cpp, 300

arrfun4.cpp, 303

arrstruc.cpp, 138

ASCII character set, 1051–1056

assgn_st.cpp, 136

assign() function, 1090, 1098

assign.cpp, 101

assignable objects, 905

assignment

assignable objects, 905

assignment functions, 1084

assignment operator (=), 45, 577, 687, 691–693

combination assignment operators, 192–193

compared to equality operator, 199–201

custom definitions, 578–579

enumerator values, setting, 142–143

overloading, 584–590

potential problems, 578

strings, 126–127

structures, 136–137

when to use, 577

assignment statements, 45

pointers, 160

strings, 126, 1090

type conversions, 100–102

variable values, 45

assignment operator (=), 45, 577, 687, 691–693

combination assignment operators, 192–193

compared to equality operator, 199, 201

custom definitions, 578–579

enumerator values, setting, 142–143

overloading, 584–590

sayings1.cpp, 588–589

string1.cpp, 586–588

string1.h, 585

potential problems, 578

strings, 126–127

structures, 136–137

when to use, 577

assignment statements, 45

associative containers, 915

functions, 1101–1102

multimap, 919–922

set, 916–919

associativity of operators

arithmetic operators, 96–97

examples, 1057–1058

table of, 1058–1061

asterisk (*), 145, 149, 160

at() function, 1083, 1099

atan() function, 318

atan2() function, 318

ATM queue simulation, 607–608

bank.cpp simulation, 621–626

Customer class, 618–621

Queue class

class declaration, 618–621

design, 608–609

implementation, 609–612

functions, 612–618

public interface, 609

auto keyword, 416

auto_ptr class, 873–877

auto.cpp, 401–402

automatic memory storage, 170–171

automatic sizing (strings), 870–872

automatic teller machine simulation. See ATM queue simulation

automatic type conversion. See type conversion

automatic variables, 170–171, 287, 399–403

example, 401–402

initializing, 403

register keyword, 405

stacks, 403–404

autoptr template, 1138

average() function, 715

B

back insert iterators, 903–905

back() function, 1099

bad() function, 272, 987–991

badbit stream state, 987–991

bad_alloc exceptions, 827–829

Balance() function, 655

bank.cpp, 622–626

Base 2 notation, 1043–1044

Base 8 notation, 1041–1042

Base 10 notation, 1041

Base 16 notation, 1042–1044

base classes

ABCs (abstract base classes), 670–672

ABC philosophy, 677

AcctABC example, 672–676

enforcing interface rules with, 677

components, initializing, 713–714

friends, 716–718

functions

accessing, 715–716

virtual functions, 739–740

objects, 716

relationships with derived classes, 643–645

TableTennisPlayer example, 634–636

using declarations, 722–723

virtual base classes, 730–731

combining with nonvirtual base classes, 742

constructors, 731–732

dominance, 742–743

functions, 732–741

base-class functions, 695

begin() function, 880–882, 1077–1078, 1097

best matches, 383–385

bidirectional iterators, 896

Big Endian, 1044

bigstep.cpp, 187

binary files, 1016–1018, 1021

binary functions, 923, 926

binary numbers, 1043–1044

binary operators, 536, 1057

binary predicates, 923, 926

binary search operations, 1115, 1119

binary.cpp, 1019

binary_search() function, 1115, 1119

binding, 161, 660–663

bitmask data type, 974

bits, 68–69, 974

bit fields, 139

clearing, 976

testing, 1069

toggling, 1069

turning off, 1069

turning on, 1068

bitwise AND operator (&), 1067

bitwise operators

alternative representations, 1067–1068

logical bitwise operators, 1065–1067

negation operator (~), 1065

OR operator (|), 1065–1066

shift operators, 518–524, 1063–1065

testing bit values, 1069

toggling, 1069

turning bits off, 1069

turning bits on, 1068

XOR operator (^), 1066

block scope, 399

block.cpp, 194

blocks, 193–195

body of functions, 32

bondini.cpp, 84

bool data type, 87–88

boolalpha manipulator, 980

bootstrap functions, 555

bottom-up programming, 15, 302

bound template friend functions, 773–775

braces ({}), 235

bracket notation, 582–583

branching statements

if, 231

bug prevention, 237

example, 232–233

syntax, 232

if else

example, 234–235

formatting, 235–236

if else if else construction, 236–237

syntax, 233

switch

enumerators as labels, 255–256

example, 252–255

syntax, 251

Brass class

class declaration, 648–657

virtual destructors, 660

virtual function behavior, 657–659

brass.cpp, 651–653

brass.h, 649

BrassPlus class

class declaration, 648–651

class implementation, 651–656

class objects, 656–657

virtual destructors, 660

virtual function behavior, 657–659

break statement, 256–259

bucks() function, 55

buffers, 953–957

Build All option (compiler), 25

buildstr() function, 312

buy() function, 456

bytes, 69

C

c_in_str() function, 310–311

C language

ANSI C, 18

C-style strings, 114–116

in arrays, 116–117

combining with numeric input, 124–125

comparing, 201–204

concatenating, 116

empty lines, 123

failbits, 123

null characters, 114

passing as arguments, 310–311

pointers, 162–166

returning from functions, 312–313

string input, entering, 118–119

string input, reading with get(), 121–123

string input, reading with getline(), 120–121

classic C, 19

development history, 13

programming philosophy, 13–14

c_str() function, 1077

C++ FAQ Lite, 1131

C++ FAQs, Second Edition, 1129

The C++ Programming Language, Third Edition, 1130

The C++ Standard Library: A Tutorial and Reference, 1129

C++ Templates: The Complete Guide, 1131

C/C++ Users Journal, 1131

calling, 33, 50, 283–284, 330

class member functions, 463

constructors, 465–466

calling.cpp, 280

callme1() function, 569

callme2() function, 570

capacity() function, 870, 1077, 1099

caret (^), 1066

carrots.cpp, 43

case sensitivity, 29, 34

casting, 103–105, 542–547, 1136–1137

downcasting, 661

upcasting, 661, 721

catch keyword, 809

catching exceptions, 809, 824

CC compiler (Unix), 22–23

cctype library, 247–249

cctypes.cpp, 248

cerr object, 456, 956

cfront translator, 22

CHAR_BIT constant, 71

char data type, 79–85, 955

escape sequences, 83–85

signed char, 86

universal character names, 85–86

unsigned char, 86

wchar_t, 86–87

CHAR_MAX constant, 71

char_type type, 1076

character strings, 38

characters

ASCII character set, 1051–1056

char data type, 79–85, 955

escape sequences, 83–85

signed char, 86

universal character names, 85–86

unsigned char, 86

wchar_t, 86–87

character strings, 38

fill, 970–971

chartype.cpp, 80

check_it.cpp, 986

cheers() function, 281–283

cin object, 47–48, 956, 983–985

get() function, 122–123, 215–217, 220–223, 290, 993–994

getline() function, 120–121

loops, 214–215

operator overloading, 985–986

stream states, 987

effects, 990–991

exceptions, 988–989

setting, 988

cinexcp.cpp, 989

cinfish.cpp, 259–260

cingolf.cpp, 261

class keyword, 375, 745

class scope, 400, 454, 487–489

class templates, 744–750

arrays, 756–758

complex, 940

explicit instantiations, 763

explicit specializations, 763–764

friend classes

bound template friend functions, 773–775

non-template friend functions, 770–773

unbound template friend functions, 775–777

implicit instantiations, 762–763

member templates, 765–768

parameters, 768–770

partial specializations, 764–765

stacks of pointers, 750–756

versatility, 758–759

default type parameters, 762

multiple type parameters, 760–762

recursive use, 759–760

classes, 48–50, 448, 461–462. See also containers; objects

ABCs (abstract base classes), 670–672

ABC philosophy, 677

AcctABC example, 672–676

enforcing interface rules with, 677

abstraction, 447

access control, 451–453

AcctABC, 672–676

ADTs (abstract data types), 489–494

ArrayDb, 706

auto_ptr, 873–877

bad_alloc, 827–829

base classes

components, initializing, 713–714

friends, accessing, 716–718

functions, accessing, 715–716

objects, accessing, 716

using declarations, 722–723

virtual base classes, 730–743

Brass

class declaration, 648–651

class implementation, 651–656

class objects, 656–657

virtual destructors, 660

virtual function behavior, 657–659

BrassPlus

class declaration, 648–651

class implementation, 651–656

class objects, 656–657

virtual destructors, 660

virtual function behavior, 657–659

changing implementation of, 486–487

class scope, 487–489

client files, 471–475

compared to structures, 453

constructors, 463–464, 475–476, 687

calling, 465–466

conversion, 688–689

copy constructors, 572–577, 686–687

declaring, 464–465

default constructors, 466–467, 571–572, 686

defining, 464–465

new operator, 590–593, 607

Customer, 618–621

data hiding, 451–452, 462

declarations, 48, 449–452, 462

defined, 14, 38, 48, 448

derived classes, 358

destructors, 463–464, 467–468, 475–476, 688

encapsulation, 451, 462

exception, 824–825

friend classes, 515–517, 787, 790–793, 796–797

compared to class member functions, 795–796

templates, 770–777

Tv class example, 788–793

header files, 469

ifstream, 1005–1008

implementation files, 469–471

inheritance

assignment operators, 691–693

base classes, 634–636, 643–645

constructors, 638–640

derived classes, 636–638, 641–645

exceptions, 829–834

has-a relationships, 645

is-a relationships, 645–646, 691

multiple, 729, 739–740

private inheritance, 712–721

what’s not inherited, 691

ios, 955

ios_base, 955, 974

iostream, 955

istream, 49, 955

data types recognized, 983–985

input functions, 999–1003

single-character input, 992–995

string input, 995–999

length restrictions, 486–487

member functions

const member functions, 475

constructors, 463–467, 475–476, 571–572, 590–593, 607

copy constructors, 572–577

definitions, 449, 453–456, 462–463

destructors, 467–468, 475–476

friend member functions, 793–798

implicit member functions, 571

inline functions, 456–457

invoking, 463

object membership, 457–458

objects, returning, 593–596

operator overloading, 524–525

private, 452–453

properties, 695–696

public, 452–453

qualified names, 454

this pointer, 477–482

unqualified names, 454

nested classes, 611, 798–800

access control, 801

scope, 800–801

templates, 801–805

ofstream, 1004–1008

ostream, 49, 955, 960–961

ostringstream, 1030–1032

protected classes, 668–669, 693

Queue

class declaration, 618–621

design, 608–609

implementation, 609–612

functions, 612–618

public interface, 609

Sales

sales.cpp, 831–832

sales.h, 829–830

use_sales.cpp, 832–834

sample program, 458–461

singleton design pattern, 669–670

Stack, 744–756

static class members, 562–571

stdexcept exception classes, 825–827

Stock, 450–451, 472

streambuf, 955

string, 125–126, 322–324, 579–580, 857–870, 1139

appending, 126–127

assignment, 126

assignment operator, overloading, 584–590

automatic sizing, 870–872

bracket notation, 582–583

comparing, 865, 872

comparison members, 581–582

complex operations, 127–129

concatenation, 126

constructors, 580–581, 858–861

copying, 128

finding size of, 865

Hangman sample program, 866–870

input, 862–864

reading line by line, 129–131

searching, 865–866

static class member functions, 583–584

STL interface, 933–934

string comparisons, 204–205

structures, 135

StringBad

constructors, 566

destructor, 567

strngbad.cpp, 564–565

strngbad.h, 562–563

vegnews.cpp sample program, 567–571

Student

contained object initialization, 706–707

contained object interfaces, 707–710

design, 703–705

functions, 709–710

private inheritance, 713–720

sample program, 710–712

studentc.h, 705–706

TableTennisPlayer, 634–635

templates, 744–750

arrays, 756–758

complex, 940

explicit instantiations, 763

explicit specializations, 763–764

friend classes, 770–777

implicit instantiations, 762–763

member templates, 765–768

parameters, 768–770

partial specializations, 764–765

stacks of pointers, 750–756

versatility, 758–762

Tv, 788–795

tv.cpp, 790–791

tv.h, 789–790

tvfm.h, 794–795

use_tv.cpp, 791–792

valarray, 702–703, 940–946

vector, 114, 525–535, 539, 878–889, 940–946

adding elements to, 881–882

adding, 526

declaring, 527–529

displacement vectors, 526

implementation comments, 537

member functions, 529–533

multiple representations, 534

overloaded arithmetic operators, 535–536

overloading overloaded operators, 536–537

past-the-end iterators, 880–881

Random Walk sample program, 538–541

removing ranges of, 881

shuffling elements in, 886

sorting, 886

state members, 533–534

vect1.cpp example, 879–880

vect2.cpp sample program, 882–885

vect3.cpp sample program, 887–889

Worker, 724–728

classic C, 19

classifying data types, 94

clear() function, 987–991, 1083, 1099, 1102

clearing bits, 976

client files, creating, 471–475

client/server model, 461

climits header file, 71–72

clock() function, 209

clog object, 956

close() function, 267

cmath header file, 319, 322

code formatting, 41–42

code listings

acctabc.cpp, 674–676

acctabc.h, 673–674

addpntrs.cpp, 156

address.cpp, 144

and.cpp, 240–241

append.cpp, 1014–1015

arith.cpp, 95

arraynew.cpp, 155

arrayone.cpp, 111

arraytp.h, 756–757

arrfun1.cpp, 293

arrfun2.cpp, 296

arrfun3.cpp, 300–303

arrstruc.cpp, 138

assgn st.cpp, 136

assign.cpp, 101

bank.cpp, 622–624

bigstep.cpp, 187

binary.cpp, 1019–1020

block.cpp, 194

bondini.cpp, 84

brass.cpp, 651–653

brass.h, 649

calling.cpp, 280

carrots.cpp, 43

cctypes.cpp, 248

chartype.cpp, 80

check_it.cpp, 986

cinexcp.cpp, 989

cinfish.cpp, 259–260

cingolf.cpp, 261

compstr1.cpp, 202

compstr2.cpp, 204

condit.cpp, 250

constcast.cpp, 850–851

convert.cpp, 58–59

copyit.cpp, 902

count.cpp, 1010

cubes.cpp, 347–348

defaults.cpp, 966–967

delete.cpp, 169

divide.cpp, 98

dma.cpp, 682–684

dma.h, 681–682

dowhile.cpp, 212

enum.cpp, 255

equal.cpp, 200

error1.cpp, 806

error2.cpp, 807–808

error3.cpp, 809–810

error4.cpp, 815–816

error5.cpp, 818–820

exc_mean.cpp, 814

exceed.cpp, 74

express.cpp, 182

filefunc.cpp, 359–360

fileio.cpp, 1006

fill.cpp, 971

firstref.cpp, 341

floatnum.cpp, 92

fltadd.cpp, 94

forloop.cpp, 178

formore.cpp, 185

forstr1.cpp, 188

forstr2.cpp, 196

frnd2tmp.cpp, 771–772

fun_ptr.cpp, 330

funadap.cpp, 929–930

functor.cpp, 924–925

funtemp.cpp, 372–373

get_fun.cpp, 996–997

getinfo.cpp, 47

hangman.cpp, 867–869

hexoct1.cpp, 77

hexoct2.cpp, 78

if.cpp, 232

ifelse.cpp, 234

ifelseif.cpp, 236

init_ptr.cpp, 149

inline_functions.cpp, 339

inserts.cpp, 904

instr1.cpp, 118

instr2.cpp, 120

instr3.cpp, 122

iomanip.cpp, 981–982

jump.cpp, 257–258

left.cpp, 363–364

leftover.cpp, 368–369

limits.cpp, 70

list.cpp, 912

listrmv.cpp, 935

lotto.cpp, 291–292

manip.cpp, 968

manyfrnd.cpp, 776–777

memb_pt.cpp, 1071–1073

modulus.cpp, 99

morechar.cpp, 80

more_and.cpp, 242–243

multmap.cpp, 920–921

myfirst.cpp, 30

mytime0.cpp, 504–505

mytime0.h, 503–504

mytime1.cpp, 507–508

mytime1.h, 506–507

mytime2.cpp, 512–514

mytime2.h, 512

mytime3.cpp, 522–523

mytime3.h, 521–522

nested.cpp, 226, 804

newexcp.cpp, 828

newstrct.cpp, 168

not.cpp, 244–245

num_test.cpp, 180

numstr.cpp, 124, 128

or.cpp, 239

ourfunc.cpp, 55

outfile.cpp, 266

pairs.cpp, 761–762

peeker.cpp, 1000–1001

placenew1.cpp, 602–603

placenew2.cpp, 604–605

plus_one.cpp, 189

pointer.cpp, 146

precise.cpp, 971–972

protos.cpp, 283

ptrstr.cpp, 162–163

queue.cpp, 619–621

queue.h, 619

queuetp.h, 802–803

random.cpp, 1026–1029

randwalk.cpp, 538–539

recur.cpp, 325

rtti1.cpp, 842–843

rtti2.cpp, 845–847

ruler.cpp, 326

sales.cpp, 831–832

sales.h, 829–830

sayings1.cpp, 588–589

sayings2.cpp, 596

secref.cpp, 343

setf.cpp, 975

setf2.cpp, 977–978

setops.cpp, 917–918

showpt.cpp, 973

sqrt.cpp, 53

stack.cpp, 491–492

stack.h, 490

stacker.cpp, 492–494

stacktem.cpp, 748–749

stacktp.h, 746–747

static.cpp, 421

stcktp1.cpp, 754–755

stcktp1.h, 752–754

stock1.cpp, 470–471

stock1.h, 469

stock2.cpp, 481–482

stock2.h, 480

stocks.cpp, 450, 454–455, 459–461

stone.cpp, 545–546

stone1.cpp, 550–551

stonewt.cpp, 543–544

stonewt.h, 542–543

stonewt1.cpp, 549–550

stonewt1.h, 548–549

str1.cpp, 858–859

str2.cpp, 871

strctfun.cpp, 318

strctptr.cpp, 321–322

strfile.cpp, 863–864

strgfun.cpp, 310

strgstl.cpp, 933–934

strin.cpp, 1031

string1.cpp, 586–588

string1.h, 585

strings.cpp, 116

strgback.cpp, 312

strngbad.cpp, 564–565

strngbad.h, 563

strout.cpp, 1030–1031

strquote.cpp, 355–356

strtref.cpp, 351–352

strtype1.cpp, 125

strtype2.cpp, 127

strtype4.cpp, 129–130

structur.cpp, 133–134

studentc.cpp, 709

studentc.h, 705–706

studenti.cpp, 717–718

studenti.h, 714

sumafile.cpp, 270–271

swaps.cpp, 345–346

switch.cpp, 252–253

tabtenn0.cpp, 635

tabtenn0.h, 634

tabtenn1.cpp, 641

tabtenn1.h, 641

tempmemb.cpp, 765–766

tempover.cpp, 385–386

tempparm.cpp, 768–769

textin1.cpp, 214

textin2.cpp, 215

textin3.cpp, 218

textin4.cpp, 221

tmp2tmp.cpp, 774–775

topfive.cpp, 323

travel.cpp, 314–315

truncate.cpp, 1002

tv.cpp, 790–791

tv.h, 789–790

tvfm.h, 794–795

twoarg.cpp, 289

twod.cpp, 759–760

twoswap.cpp, 377–379

twotemps.cpp, 374–375

typecast.cpp, 104–105

use_new.cpp, 151–152

use_sales.cpp, 832–834

use_stuc.cpp, 710–712

use_stui.cpp, 719

use_tv.cpp, 791–792

usealgo.cpp, 938–939

usebrass1.cpp, 656

usebrass2.cpp, 657–658

usedma.cpp, 685

usenmsp.cpp, 436

usesstok2.cpp, 484

usestok1.cpp, 472

usetime0.cpp, 505–506

usetime1.cpp, 508–509

usetime2.cpp, 514

usetime3.cpp, 523–524

usett0.cpp, 635

usett1.cpp, 642–643

valvect.cpp, 943

vect.cpp, 529–532

vect.h, 528–529

vect1.cpp, 879–880

vect2.cpp, 883–884

vect3.cpp, 887–888

vegnews.cpp, 567–568

vslice.cpp, 944–945

waiting.cpp, 210

while.cpp, 206

width.cpp, 969–970

Worker0.cpp, 725–727

Worker0.h, 724–725

workermi.cpp, 737–739

workermi.h, 735–736

workmi.cpp, 739–740

worktest.cpp, 727

write.cpp, 962–963

code style, 42

CodeWarrior (Metrowerks), 26–27

colon (:), 453

combination assignment operators, 192–193

comma operator (,), 195–198

example, 196–197

precedence, 198

command-line processing, 1008–1009

commands. See specific command names

comments, 29

/*...*/ notation, 35

// notation, 34–35

compare() function, 1088–1089

comparing strings, 865, 872, 1088–1089

C-style strings, 201–204

string class strings, 204–205

comparison members (String class), 581–582

compatibility, 30

compile time, 145, 907

compilers

CC (Unix), 22–23

definition of, 13

g++ (Linux), 23–24

gpp, 24

Metrowerks CodeWarrior, 26–27

troubleshooting, 25

Windows, 24–26

complex class template, 940

composition, 701

compound statements (blocks), 193–195

compound types, 110. See also arrays; strings

enumerations

enumerators, 141–142

value ranges, 143

values, setting, 142–143

pointers

assigning values to, 160

C++ philosophy, 145

cautions, 149

compared to pointed-to values, 160

declaring, 146–149, 159

dereferencing, 160

delete operator, 152–153

example, 144–145

initializing, 147–149

integers, 150

new operator, 150–152

pointer arithmetic, 156–161

pointer notation, 161

pointers to objects, 596–601

strings, 162–166

structures, 131–133

arrays, 137–139

assignment, 136–137

bit fields, 139

dynamic structures, 166, 168

example, 133–135

members, 132

string class members, 135

unions

anonymous unions, 140–141

declaring, 139

compstr1.cpp, 202

compstr2.cpp, 204

concatenation

output, 48, 960–961

strings, 116, 122, 126–127, 1090

concatenation operator (+), 126–127

condit.cpp, 250

conditional operator (?:), 250–251

const_cast operator, 849–850

const_iterator type, 1095

const keyword, 88–89, 416–418, 690

as alternative to #define, 1133–1135

arrays, 299–300

const objects, returning references to, 593–596

member functions, 475

pointers, 305–308

reference variables, 354–355

temporary variables, 349–351

const_reference type, 1095

constant time complexity, 907

constants, 76–79. See also strings

char data type, 79–85, 955

escape sequences, 83–85

signed char, 86

universal character names, 85–86

unsigned char, 86

wchar_t, 86–87

const keyword, 88–89, 416–418, 690

as alternative to #define, 1133–1135

arrays, 299–300

const objects, returning references to, 593–596

member functions, 475

pointers, 305–308

reference variables, 354–355

temporary variables, 349–351

file modes, 1011–1013

floating-point constants, 93

representing bit values, 974

size_type, 1076

symbolic constants, 71–72

symbolic names, 88–89

constcast.cpp, 850–851

constructors, 463–464, 665, 687

calling, 465–466

conversion, 688–689

copy constructors, 686–687

deep copying, 575–577

limitations, 574–575

shallow copying, 573

when to use, 572–573

declaring, 464–465

default constructors, 466–467, 571–572, 686

defining, 464–465

inheritance, 638–640

new operator, 590–593, 607

string class, 1078

constructors that use arrays, 1079–1080

constructors that use n copies of character, 1081

constructors that use parts of arrays, 1080

constructors that use ranges, 1082

copy constructors, 1080–1081

default constructors, 1079

Stock, 472

String, 580–581, 858–861

virtual base classes, 731–732

contained objects

compared to private inheritance, 720–721

initializing, 706–707

interfaces, 707–710

containers, 490, 701, 744, 905

associative, 915

multimap, 919–922

set, 916–919

contained objects

compared to private inheritance, 720–721

initializing, 706–707

interfaces, 707–710

deques, 910, 1098–1100

lists, 910–913, 1098–1100

maps, 1101–1102

functions, 934–936, 1097–1098

priority_queue, 914

properties, 906–907

queue, 913–914

sequence requirements, 907–909

sets, 1101–1102

stacks, 494, 914–915

vectors, 910, 1098–1100

continue statement, 256–259

conversion constructors, 688–689

convert.cpp, 58–59

converting

data types, 100, 541–547, 606

applying automatically, 551–552

conversion functions, 547–551

conversion in arguments, 103

conversion in expressions, 102–103

conversion on assignment, 100–102

friends, 553–555

implicit conversion, 544

type casts, 103–105, 542–547

rectangular coordinates to polar coordinates, 317–320

to standard C++

autoptr template, 1138

C++ features, 1137

const instead of #define, 1133–1135

function prototypes, 1136

header files, 1137

inline instead of #define, 1135–1136

namespaces, 1137–1138

STL (Standard Template Library), 1139–1140

string class, 1139

type casts, 1136–1137

coordin.h, 395–396

coordinates

converting, 317–320

polar coordinates, 316–317

rectangular coordinates, 316

copy constructible objects, 905

copy constructors, 572, 686–687

deep copying, 575–577

limitations, 574–575

shallow copying, 573

when to use, 572–573

copy_backward() function, 1107, 1109

copy() function, 899–900, 1093, 1107–1109

copying

algorithms, 932

deep copying, 575–577

shallow copying, 573

strings, 127–128, 1093

copyit.cpp, 902

count() function, 774, 937, 1102–1105

count.cpp, 1010

count_if() function, 1103, 1106

counts() function, 773

cout object, 39, 956–958

buffers, flushing, 964–965

concatenation, 48, 960–961

endl manipulator, 40

field width display, 969–970

fill characters, 970–971

floating-point display precision, 971–972

formatting data types, 965–967

integer values, displaying, 46

functions, 81–82, 961–964

newline character, 40–41

number base display, 967, 969

overloaded << operator, 958–959

printing trailing zeros/decimal points, 972–979

covariance of return type, 667

.cpp filename extension, 30

CRC cards, 1032

cstring header file, 116–117

ctime header file, 209

cube() function, 283, 286, 348

cubes.cpp, 347–348

cumulative totals, 1127

Customer class, 618–621

cv-qualifiers, 415–417

const, 416–418

volatile, 416

D

data hiding, 451–452, 462

data types, 447–448. See also compound types,

ADTs (abstract data types), 489–494

aliases, 210–211

bool, 87–88

char_type, 1076

classifying, 94

compound types, 110

const_iterator, 1095

const_reference, 1095

design issues, 494

difference_type, 1076, 1095

double, 52

floating-point numbers

advantages/disadvantages, 94

constants, 93

decimal-point notation, 89

double, 91–93

E notation, 90

float, 91–93

long double, 91–93

integers

char, 79–87

choosing integer types, 75–76

climits header file, 71–72

constants, 76–79, 88–89

initializing, 72–73

int, 68–71

long, 68–71

short, 68–71

sizeof operator, 71–72

unsigned, 73–75

width of, 68

iterators, 894–895, 1095

key_compare, 1101

key_type, 1101

mapped_type, 1101

recognized by << insertion operator, 958–959

reference, 1095

size_type, 1076, 1095

traits, 1076

type casts, 103–105, 542–547

type conversion, 541–547

applying automatically, 551–552

conversion functions, 547–551

conversion in arguments, 103

conversion in expressions, 102–103

conversion on assignment, 100–102

friends, 553–555

implicit conversion, 544

value_compare, 1101

value_type, 1095

data() function, 734, 1077–1078

dec manipulator, 968–969, 980

decimal numbers, 1041

decimal points, trailing, 972–979, 982

declarative region, 424

declarations, 43–45, 184–185, 409

arrays, 110–113, 483

class member functions, 453–456

classes, 48, 449–452, 462

constructors, 464–465

function pointers, 328–331

functions, 280–283

pointers, 146–149, 159

two-dimensional arrays, 224–225

unions, 139

variables, 43–45, 171

vector class, 527, 529

decorating names, 370

decrement operator (—), 189–192

deep copying, 575–577

default arguments, 362–365

default class constructors, 466–467

default constructors, 571–572, 686

default type template parameters, 762

defaults.cpp, 966

#define directive, converting to standard C++

const instead of #define, 1133–1135

inline instead of #define, 1135–1136

delete operator, 152–153, 168–171, 354, 399, 419–420, 599

delete.cpp, 169

deprecation, 432

deques, 910, 1098–1100

dequeue() function, 617

dereferencing operator, 145–149, 160, 1070–1073

derived classes, 358

constructors, 638–640

creating, 636–638

header files, 641

function definitions, 641–642

objects, creating, 642–643

relationships with base classes, 643–645

derived types, 110

design

bottom-up, 15

singleton design pattern, 669–670

top-down, 14

The Design and Evolution of C++, 693, 1131

destructors, 463–464, 467–468, 475–476, 688

virtual destructors, 660, 665, 694

difference_type type, 1076, 1095

directives

#define, 1133–1136

#include, 36

using, 37–38, 60–61, 428–431

displacement vectors, 526

divide-and-conquer strategy, 326–327

divide.cpp, 98

division operator (/), 97–98

dma.cpp, 682–684

dma.h, 681–682

do while loops, 211–213

dominance, 742–743

double data type, 52, 91–93

double-ended queues (deques), 910, 1098–1100

dowhile.cpp, 212

downcasting, 661

Draw() function, 733

dribble() function, 367

dynamic arrays, 161

creating, 153–155

new operator, 154

sample program, 155–156

dynamic binding, 153, 161, 660–663

dynamic cast operators, 840–849

dynamic memory allocation, 419–423, 677

auto_ptr class, 873–877

derived class does use new, 679–680

derived class doesn’t use new, 677–678

example, 681–685

dma.cpp, 682–684

dma.h, 681–682

usedma.cpp, 685

dynamic storage duration, 399

dynamic structures, 166–168

dynamic variables, 399

E

early binding, 660

Effective C++: 50 Specific Ways to Improve Your Programs and Designs, Second Edition, 1130

Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library, 1130

empty lines in strings, 123

empty() function, 1083, 1097

encapsulation, 451, 462

end() function, 880–882, 1077, 1097

end-of-file conditions, 217–220

endl manipulator, 40

enqueue() function, 799

entry-condition loops, 180

enum statement, 255–256

enum variables

enumerators, 141–142, 255–256

value ranges, 143

values, setting, 142–143

enum.cpp, 255

enumerations

enumerators, 141–142, 255–256

value ranges, 143

values, setting, 142–143

enumerators, 141–142, 255–256

EOF (end-of-file) conditions, 217–220

eof() function, 217, 272, 987–991

eofbit stream state, 987–991

equal sign (=)

assignment operator (=), 687, 691–693

custom definitions, 578–579

enumerator values, setting, 142–143

overloading, 584–590

potential problems, 578

strings, 126–127

structures, 136–137

when to use, 577

equality operator (==), 199–201

equal() function, 1103, 1106

equal_range() function, 920, 1115, 1119

equal_range() function, 1102

equal.cpp, 200

equality operator (==), 198–201

erase() function, 881–882, 1091, 1098, 1102

erasing strings, 1091–1092

error handling. See exception handling

error1.cpp, 806

error2.cpp, 807–808

error3.cpp, 809–810

error4.cpp, 815–816

error5.cpp, 818–820

escape sequences, 83

estimate() function, 328–331

eternal loops, 213

exact matches, 383–385

exc_mean.cpp, 814

exceed.cpp, 74

exception class, 824–825

exception handling, 805, 808–809, 839

abort() function, 805–807

bad_alloc exceptions, 827–829

catching exceptions, 809, 824

cautions, 837–839

error codes, 807–808

exception class, 824–825

exception specifications, 813

inheritance

sales.cpp, 831–832

sales.h, 829–830

use_sales.cpp, 832–834

invalid_argument exceptions, 826

length_error exceptions, 826

logic_error exceptions, 826

objects as exceptions, 812–816

out_of_bounds exceptions, 826

range_error exceptions, 827

real-world note, 839

runtime_error exceptions, 826

stdexcept exception classes, 825–827

throwing exceptions, 809, 822–823

try blocks, 809–811

uncaught exceptions, 834–837

unexpected exceptions, 834–837

unwinding the stack, 816–822

exceptions() function, 987–991

exclamation point (!), 244–247

executable code, 20

exit() function, 456, 836

explicit instantiation, 380–382, 545, 763

explicit specializations, 376, 545, 763–764

earlier approaches to, 379–380

example, 377–379

third-generation specialization, 376–377

express.cpp, 182

expressions, 95, 181–183

arguments, 757

combining with comma operator, 195

compared to statements, 183

conditional (?:), 250–251

declaration-statement expressions, 184–185

logical AND (&&), 239

alternative representations, 247

example, 240–242

precedence, 246–247

ranges, 242–244

logical NOT (!), 244–247

logical OR (||), 238–239

alternative representations, 247

example, 239

precedence, 246

relational operators, 198–201

C-style strings, comparing, 201–204

equality operator (==), 199–201

string class strings, comparing, 204–205

table of, 198

sequence points, 190

side effects, 183, 190

type conversions, 102–103

ext_permutation() algorithm, 933

extern keyword, 410–413, 416–418

external arrays, 243

external declarations, 134

external linkage, 399

external variables, 408–410

external.cpp, 408–409

F

factorials, calculating, 185–187

fail() function, 272, 991, 987–991

failbits, 123, 987–991

file_it() function, 361

file scope, 399

file1.cpp, 397

file2.cpp, 397

filefunc.cpp, 359–360

fileio.cpp, 1006

files. See also names of specific files

associating objects with, 265

client files, 471–475

climits, 71–72

cmath, 319

command-line processing, 1008–1009

compiling separately, 393–395, 398

.cpp filename extension, 30

EOF (end-of-file) conditions, 217–219

file modes

appending data to files, 1014–1016

binary, 1016–1018, 1021

constants, 1011–1013

opening files, 1013–1014

text, 1018

header files, 36–37, 394–395

converting to standard C++, 1137

creating, 469

cstring, 116–117

managing, 396

implementation files, 469–471

include files, 93

opening multiple, 1008

random access, 1021–1029

reading, 268–273, 1005–1007

stream states, checking, 1007–1008

text files, 263–264

writing, 264–268, 1004–1007

fill characters, 970–971

fill() function, 970, 1108, 1111

fill.cpp, 971

fill_array() function, 298–302

fill_n() function, 1108, 1111

fillArray() function, 297

filling arrays, 298–299

fin.clear() function, 1010

find() function, 865–866, 869–872, 1084–1085, 1102–1104

find_arr() function, 891

find_end() function, 1103–1105

find_first_not_of() function, 866, 1087

find_first_of() function, 1103–1105

find_first_of() function, 866, 1086

find_if() function, 1103–1104

find_last_not_of() function, 1087

find_last_of() function, 866, 1086

firstref.cpp, 341

fixed manipulator, 980

flags, 973. See also setf() function

float data type, 91–93

floating-point numbers, 89

advantages/disadvantages, 94

constants, 93

decimal-point notation, 89

default behavior, 965

display precision, 971–979

double data type, 91–93

E notation, 90

float data type, 91–93

long double data type, 91–93

floatnum.cpp, 92

fltadd.cpp, 94

flush() function, 965

flushing buffers, 954

for_each() function, 885–889, 1103–1104

for loops

blocks, 193–195

body, 178–179

combination assignment operators, 192–193

comma operator, 195–198

compared to while loops, 207–209

declaration-statement expressions, 184

decrement operator, 189–192

example, 178–179

expressions, 181–183

compared to statements, 183

declaration-statement expressions, 184–185

factorials, calculating, 185–187

increment operator, 189–192

initialization, 178–179

loop test, 178–179

loop updates, 178–180, 187–188

nested loops, 223–227

nonexpressions, 184

sequence points, 190

side effects, 183, 190

step size, 187–188

strings, 188

syntax, 179–181

forever loops, 213

forloop.cpp, 178

formal arguments, 287

formatted input functions, 983

formatting

with cout, 965–967

field width display, 969–970

fill characters, 970–971

floating-point display precision, 971–972

manipulators, 980

number base display, 967–969

trailing zeros/decimal points, 972–979

if else statement, 235–236

incore, 1030–1032

with iomanip header file manipulators, 981–982

source code, 41–42

formore.cpp, 185

forstr1.cpp, 188

forstr2.cpp, 196

forward declaration, 793

forward iterators, 896

free store (memory), 170–171, 399

freeing memory, 152–153

friend classes, 515–517, 787, 790–793, 796–797

base-class friends, accessing, 716–718

compared to class member functions, 795–796

templates

bound template friend functions, 773–775

non-template friend functions, 770–773

unbound template friend functions, 775–777

Tv class example, 788–789, 793

tv.cpp, 790–791

tv.h, 789–790

tvfm.h, 794–795

use_tv.cpp, 791–792

friend functions, 515–517, 793

compared to friend classes, 795–796

creating, 516–517

example, 794–795

forward declaration, 793

shared friends, 797–798

type conversion, 553–555

friend keyword, 516–517

frnd2tmp.cpp, 771–772

front insert iterators, 903–905

front() function, 1099

fun_ptr.cpp, 330

funadap.cpp, 929–930

function objects. See functors

functional polymorphism, 502

functions, 20, 31, 50. See also names of specific functions

adaptable binary, 929–930

adaptable unary, 929–930

algorithms, 930–933

arguments, 33, 51, 54–55

arrays, 295–297

multiple, 288–292

passing by value, 286–287

two-dimensional arrays, 308–309

arrays, 293–294

as arguments, 295–297

const keyword, 299–300

design decisions, 297–298

displaying contents of, 299–300

examples, 300–303

filling, 298–299

modifying, 300

pointers, 294–295

ranges, 303–304

two-dimensional arrays, 308–309

binary, 923, 926

body, 32

bootstrap functions, 555

calling, 33, 50, 283–284

case sensitivity, 29, 34

class member functions

const member functions, 475

constructors, 463–467, 475–476, 571–572, 590–593, 607

copy constructors, 572–577

definitions, 449, 453–456, 462–463

destructors, 467–468, 475–476

friend member functions, 793–798

implicit member functions, 571

inline functions, 456–457

invoking, 463

object membership, 457–458

objects, returning, 593–596

operator overloading, 524–525

private, 452–453

properties, 695–696

public, 452–453

qualified names, 454

this pointer, 477–482

unqualified names, 454

compared to container functions, 934–936

conversion functions, 606

defining, 32, 280–283

formatted input, 983

friend functions, 515–517

creating, 516–517

type conversion, 553–555

headers, 32–34

inline functions, 337–340

library functions, 53

linkage, 418–419

non-member functions, 885–889

objects, returning, 593–595

const objects, 593–596

non-const objects, 594

overloading, 216, 365–367, 502

example, 367–369

function signatures, 365

name decoration, 370

overload resolution, 382–388

when to use, 370

pointers, 327–328

addresses of functions, obtaining, 328

const keyword, 305–308

declaring, 328–329

example, 330–331

invoking functions with, 330

pointers to pointers, 305–306

polymorphism, 365

prototypes, 51–54, 283–285, 1136

benefits, 285–286

C++ compared to ANSI C, 285

scope, 400

syntax, 285

qualified names, 454

recursion

multiple recursive calls, 326–327

single recursive call, 324–326

return addresses, 816

return types, 33

return values, 50–51

signatures, 365

string class objects, 322–324

structures, 313–316

passing/returning, 314–320

polar coordinates, 316–317

rectangular coordinates, 316

structure addresses, passing, 320–322

templates, 370–374

explicit instantiation, 380–382

explicit specializations, 376–380

implicit instantiation, 380–382

overload resolution, 382–388

overloading, 374–376

unary, 923, 926

unqualified names, 454

user-defined functions

example, 55–56

function form, 56

function headers, 56–58

return values, 58–60

using directive, 60–61

virtual functions, 671

void, 281

functor.cpp, 924–925

functors, 922–923

adaptable, 928

concepts, 923–926

predefined, 926–928

funtemp.cpp, 372–373

G

g++ compiler, 23–24

gcount() function, 999–1003

generate() function, 1108, 1111

generate_n() function, 1108, 1111

generators, 923

get() function, 121–123, 215–217, 220–223, 735, 992–999

get_allocator() function, 1077

get_fun.cpp, 996

getinfo.cpp, 47

getline() function, 120–121, 449, 728, 862–864, 995–999, 1093

getname() function, 168–170

global namespaces, 426

global objects, 555

global scope, 399

global variables, 410

good() function, 270, 987–991

goodbit stream state, 987–991

gpp compiler, 24

greater than operator (>), 198

greater than or equal to operator (>=), 198

H

handling exceptions. See exception handling

hangman.cpp, 867–869

harmonic mean, 805

harpo() function, 363

has-a relationships, 645, 703–705

header files, 394–395

climits, 71–72

cmath, 319, 322

converting to standard C++, 1137

creating, 469

cstring, 116–117

ctime, 209

filenames, 36–37

iomanip, 981–982

iostream, 265

managing, 396

headers (function), 32–34, 56–58

heaps (memory), 170

creating, 1123

defined, 1123

heap operations

make_heap() function, 1116, 1123

pop_heap() function, 1116, 1123

push_heap() function, 1116, 1123

sort_heap() function, 1116, 1124

popping values off, 1123

pushing values onto, 1123

sorting, 1124

hex manipulator, 968–969, 980

hexadecimal numbers, 1042–1044

hexoct1.cpp, 77

hexoct2.cpp, 78

high-level languages, 13

history of C++, 12–17

C language, 13–14

generic programming, 15–16

OOP, 14–15

hmean() function, 807–814

I

I/O, 952

buffers, 953–957

cin object, 47–48, 956, 983–985

get() function, 122–123, 215–217, 220–223, 290, 993–994

getline() function, 120–121

loops, 214–215

operator overloading, 985–986

stream states, 987–991

cout object, 39, 956–958

buffers, flushing, 964–965

concatenation, 48, 960–961

endl manipulator, 40

field width display, 969–970

fill characters, 970–971

floating-point display precision, 971–972

formatting data types, 965–967

integer values, displaying, 46

functions, 81–82, 961–964

newline character, 40–41

number base display, 967, 969

overloaded << operator, 958–959

printing trailing zeros/decimal points, 972–979

file I/O, 1003

checking stream states, 1007–1008

command-line processing, 1008–1009

file modes, 1011–1018, 1021

opening multiple files, 1008

random access, 1021–1029

reading, 1005–1007

writing, 1004–1007

input functions

formatted, 983

unformatted, 991

redirecting, 957–958

streams, 952–957

strings, 1093–1094

IDEs (integrated development environments), 20

if else statement

example, 234–235

formatting, 235–236

if else if else construction, 236–237

syntax, 233

if statement, 231

bug prevention, 237

example, 232–233

syntax, 232

if.cpp, 232

ifelse.cpp, 234

ifelseif.cpp, 236

ifstream objects, 1005–1008

ignore() member function, 995–997

implementation files, 469–471

implicit conversion, 544

implicit instantiation, 380–382, 762–763

implicit keyword, 545

implicit member functions, 571

implicit upcasting, 721

in-place algorithms, 932

#include directive, 36

include files, 93

includes() function, 1115, 1121

incore formatting, 1030–1032

increment operator (++), 178, 189–192

indeterminate values, 72

indexes, 110–111

indirect values, 145

inequality operator (!=), 198

inheritance, 634

ABCs (abstract base classes), 670–672

ABC philosophy, 677

AcctABC example, 672–676

enforcing interface rules with, 677

assignment operators, 691–693

base classes

relationships with derived classes, 643–645

TableTennisPlayer example, 634–636

constructors, 638–640

derived classes

creating, 636–638

header files, 641

function definitions, 641–642

objects, creating, 642–643

relationships with base classes, 643–645

dynamic memory allocation

derived class does use new, 679–680

derived class doesn’t use new, 677–678

example, 681–685

exceptions, 829–834

sales.cpp, 831–832

sales.h, 829–830

use_sales.cpp, 832–834

has-a relationships, 645

is-a relationships, 645–646, 691

multiple inheritance, 713, 723–724

virtual base classes, 730–743

Worker class example, 724–729

polymorphic public inheritance, 647–648, 721, 739–740

base-class functions, 695

Brass class declaration, 648–651

Brass class implementation, 651–656

Brass class objects, 656–657

BrassPlus class declaration, 648–651

BrassPlus class implementation, 651–656

BrassPlus class objects, 656–657

constructors, 665

dynamic binding, 660–663

pointer compatibility, 660–662

reference type compatibility, 660–662

static binding, 660–663

virtual destructors, 660, 665, 694

virtual functions, 657–659, 662–667, 693–694

private inheritance, 712–713

base-class components, initializing, 713–714

base-class friends, accessing, 716–718

base-class functions, accessing, 715–716

base-class objects, accessing, 716

compared to containment, 720–721

Student class example, 713, 718–720

protected classes, 668–669, 693

protected inheritance, 721–722

references, 358–361

what’s not inherited, 691

init_ptr.cpp, 149

initialization

arrays, 111–114

arrays of objects, 483

two-dimensional arrays, 225–227

automatic variables, 403

base-class components, 713–714

contained objects, 706–707

for loops, 178–179

initialization lists, 113

pointers, 147–149

reference variables, 342

strings, 114–115

variables, 54, 72–73

inline functions, 337–338, 456–457

compared to macros, 340

square(), 339–340

inline modifier, 456, 1135–1136

inline.cpp, 339

inner_product() function, 1127

inplace_merge() function, 1115, 1120

input functions

formatted, 983

unformatted, 991

input iterators, 895

input/output. See I/O

insert iterators, 903–905

insert() function, 882, 911–913, 1091, 1098, 1102

insertion operator

concatenation, 960–961

data types recognized, 958–959

pointers, 960

inserts.cpp, 904

instances, 450

instantiation, 746–750

explicit, 380–382, 763

implicit, 380–382, 762–763

instr1.cpp, 118

instr2.cpp, 120

instr3.cpp, 122

int data type, 68–71

int main() function header, 33–34

INT_MAX constant, 72

INT_MIN constant, 72

integers, 68

bool, 87–88

char, 79–85

escape sequences, 83–85

signed char, 86

universal character names, 85–86

unsigned char, 86

wchar_t, 86–87

choosing integer types, 75–76

climits header file, 71–72

constants, 76–79, 88–89

displaying with cout, 46

initializing, 72–73

int, 68–71

long, 68–71

pointers, 150

short, 68–71

sizeof operator, 71–72

unsigned, 73–75

width of, 68

integrated development environments (IDEs), 20

interfaces

contained objects, 707–710

defined, 449

public interfaces, 449

internal linkage, 399

internal manipulator, 980

internal variables, 410–413

International Standards Organization. See ISO

Internet resources, 1131

invalid_argument exception, 826

invoking. See calling

iomanip.cpp, 981

ios_base class, 955, 974

ios class, 955

iostream class, 955

iostream file, 35–36, 265, 955–957

is-a relationships, 645–646, 691, 723

is_open() function, 269, 1007–1008, 1014–1016

isalnum() function, 249

isalpha() function, 249

isblank() function, 249

iscntrl() function, 249

isdigit() function, 249

isempty() function, 614

isfull() function, 614

isgraph() function, 249

islower() function, 249

ISO (International Standards Organization), 18

ISO 10646, 86

ISO/ANSI C++ Standard, 1131

isprint() function, 249

ispunct() function, 249

isspace() function, 249, 990

istream class, 49, 955

data types recognized, 983, 985

input

functions, 999–1003

single-character, 992–995

strings, 995–999

istream iterator template, 901

isupper() function, 249

isxdigit() function, 249

iter_swap() function, 1108

iterators, 880–881, 898–890, 894–895, 1095

back insert, 903–905

bidirectional, 896

copy() function, 899–900

forward, 896

front insert, 903–905

hierarchy, 897–898

importance of, 890–894

input, 895

insert, 903–905

istream iterator template, 901

ostream iterator template, 900–901

output, 895

pointers, 899

random access, 896–897

reverse, 901–903

types, 894–895

J-K

jump.cpp, 257–258

K&R (Kernighan and Ritchie) C standard, 19

key_comp() function, 1101

key_compare type, 1101

key_type type, 1101

keywords, 58. See also statements

auto, 416

catch, 809

class, 375, 745

const, 88–89, 416–418, 690, 1133–1135

arrays, 299–300

pointers, 305–308

reference variables, 354–355

temporary variables, 349–351

explicit, 545

extern, 410–413, 416–418

friend, 516–517

implicit, 545

inline, 456, 1135–1136

mutable, 416–417

namespace, 426–427

private, 451–453, 713

protected, 668–669, 693, 721

public, 451–453

register, 405, 416

static, 171, 243, 416–418

struct, 132

table of, 1047

template, 745

throw, 809

try, 809

typedef, 210

typename, 371–372, 375, 745

using, 427–431, 722–723, 1137–1138

virtual, 664

volatile, 416

L

labels, enumerators as, 255–256

language divergence, 18

language linking, 419

last in-first out (LIFO) stacks, 404

late binding, 660

layering, 701

leaks (memory), 171

Lee, Meng, 878

left manipulator, 980

left shift and assign operator (<<=), 1064

left shift operator (<<), 518–524, 606, 1063–1064

left() function, 362–363, 367–370

left.cpp, 363–364

leftover.cpp, 368–369

length_error exception, 826

length() function, 865, 1075–1077

less than operator (<), 198

less than or equal to operator (<=), 198

lexicographical_compare() function, 1116, 1125

libraries, 20. See also STL (Standard Template Library)

cctype, 247–249

multiple library linking, 398

LIFO (last in-first out) stacks, 404

limits.cpp, 70

linear time complexity, 907

linkage

external, 399

functions, 418

internal, 399

language linking, 419

libraries, 398

linked lists, 610

static variables

external linkage, 408–410

internal linkage, 410–413

no linkage, 413–415

Linux g++ compiler, 23–24

list.cpp, 912–913

listrmv.cpp, 935

lists

class templates, 910–913

containers, 910–913

linked lists, 610

functions, 1098–1100

Little Endian, 1044

local scope, 399–403

local variables, 287–288, 410

logic_error exception, 826

logical operators, 238, 1065–1067

alternative representations, 247

AND (&&), 239

alternative representations, 247

example, 240–242

precedence, 246–247

ranges, 242–244

functor equivalents, 927–928

NOT (!), 244–245

alternative representations, 247

precedence, 246

OR (||), 238–239

alternative representations, 247

example, 239

precedence, 246

long data type, 68–71

long double data type, 91–93

LONG_MAX constant, 72

LONG_MIN constant, 72

loops, 177. See also expressions

break statement, 256–259

continue statement, 256–259

do while, 211–213

entry-condition loops, 180

for loops

blocks, 193–195

body, 178–179

combination assignment operators, 192–193

comma operator, 195–198

compared to while loops, 207–209

decrement operator (—), 189–192

example, 178–179

expressions, 181–185

factorials, calculating, 185–187

increment operator (++), 189–192

initialization, 178–179

loop test, 178–179

loop updates, 178–180, 187–188

nonexpressions, 184

sequence points, 190

side effects, 183, 190

step size, 187–188

strings, 188

syntax, 179–181

forever loops, 213

nested loops, 223–227

number-reading loops, 259–262

text input, 213

cin object, 214–215

cin.get() function, 215–217, 220–223

end-of-file conditions, 217–220

sentinel characters, 214

while loops

compared to for loops, 207–209

example, 205–207

syntax, 205

time-delay loops, 209–210

lotto probabilities, calculating, 290–292

lotto.cpp, 291–292

low-level languages, 13

lower_bound() function, 917, 920, 1102, 1115, 1119

M

machine language, 19

Macintosh Metrowerks CodeWarrior, 26–27

macros, 340

magval() function, 537

main() function, 31–32

calling, 33

importance of, 34

int main() header, 33–34

make_heap() function, 1116, 1123

malloc() function, 150

mangling names, 370

manip.cpp, 968

manipulators, 980

endl, 40

iomanip header file, 981–982

number base display, 967–969

mantissas, 90

manyfrnd.cpp, 776–777

mapped_type type, 1101

math operators. See arithmetic operators

max() function, 703, 941, 1116, 1124

max_element() function, 1116, 1125

max_size() function, 1077

maximum values, finding, 1124

maxsize() function, 1097

mean, harmonic, 805

means() function, 817–822

memb_pt.cpp, 1071, 1073

member dereferencing operators, 1070–1073

member functions. See also names of specific functions

const member functions, 475

constructors, 463–464, 665, 687

calling, 465–466

conversion, 688–689

copy constructors, 572–577, 686–687

declaring, 464–465

default constructors, 466–467, 571–572, 686

defining, 464–465

inheritance, 638–640

new operator, 590–593, 607

string class, 1078–1082

Stock, 472

String, 580–581, 858–861

virtual base classes, 731–732

definitions, 449, 453–456, 462–463

destructors, 467–468, 475–476

friend member functions, 515–517, 793

compared to friend classes, 795–796

example, 794–795

forward declaration, 793

shared friends, 797–798

implicit member functions, 571

inline functions, 456–457

invoking, 463

object membership, 457–458

objects, returning, 593–595

private, 452–453

properties, 695–696

public, 452–453

qualified names, 454

template classes, 911–913

this pointer, 477–482

unqualified names, 454

virtual functions, 662–665, 693–694

behavior, 657–659

friends, 666, 694

memory and execution speed, 664

pure virtual functions, 671

redefinition, 666–667

virtual function tables, 663

member initializer lists, 487, 612, 640

member templates, 765–768

memberwise assignment, 136

memberwise copying, 573

memory

allocating

bad_alloc exceptions, 827–829

dynamic memory allocation, 419–423, 677–685, 873–877

new operator, 150–152

automatic storage, 170–171

buffers, 953–957

cv-qualifiers, 415–418

dynamic, 419–423, 677–685, 873–877

free store, 170–171

freeing, 152–153

function linkage, 418

language linking, 419

leaks, 153, 171

memory-related functions, 1082–1083

named, 150

stack, 403–404, 816–822

static storage, 171

storage class specifiers, 415–417

storage duration

automatic variables, 400–405

scope and linkage, 399–400

static variables, 406–415

storage functions, 170

merge() function, 913, 1100, 1115, 1120

methods. See member functions

Metrowerks CodeWarrior, 26–27

MI. See multiple inheritance

min_element() function, 1116, 1124

min() function, 703, 941, 1116, 1124

minimum values, finding, 1124

mismatch() function, 1103, 1106

modifiers. See keywords

modulus operator (%), 99–100

modulus.cpp, 99

more_and.cpp, 242–243

More Effective C++: 35 New Ways to Improve Your Programs and Designs, 1130

morechar.cpp, 80

Move() function, 671

MS-DOS gpp compiler, 24

multifile programs, compiling separately, 393–395, 398

multimap associative containers, 919–922

multiple arguments

n_chars() example, 288–290

probability() example, 291–292

multiple class representations, 534

multiple inheritance, 713, 723–724

virtual base classes, 730–731

combining with nonvirtual base classes, 742

constructors, 731–732

dominance, 742–743

functions, 732–741

Worker class example, 724–729

multiple library linking, 398

multiple public inheritance, 739–740

multiple type parameters, 760–762

multiplication operator (*), 512–515

multiset operations

includes() function, 1121

set_difference() function, 1122–1123

set_intersection() function, 1121

set_union() function, 1121

multmap.cpp, 920–921

mutable keyword, 416–417

mutating sequence operations

copy(), 1107–1109

copy_backward(), 1107–1109

fill(), 1108, 1111

fill_n(), 1108, 1111

generate(), 1108, 1111

generate_n(), 1108, 1111

iter_swap(), 1108

partition(), 1109, 1114

random_shuffle(), 1109, 1114

remove(), 1108, 1112

remove_copy(), 1108, 1112

remove_copy_if(), 1108, 1112

remove_if(), 1108, 1112

replace(), 1108–1110, 1114

replace_copy(), 1108, 1111

replace_copy_if(), 1108, 1111

replace_if(), 1108, 1111

reverse(), 1108

reverse_copy(), 1108, 1113

rotate(), 1109, 1114

rotate_copy(), 1109, 1114

stable_partition(), 1109, 1114

swap(), 1107, 1110

swap_ranges(), 1108–1110

transform(), 1108–1110

unique(), 1108, 1113

unique_copy(), 1108, 1113

myfirst.cpp program, 29–31

comments, 34–35

header filenames, 36–37

iostream file, 35–36

main() function, 31–32

calling, 33

importance of, 34

int main() header, 33–34

namespaces, 37–38

output, displaying with cout, 39–41

source code formatting, 41–42

mytime0.h, 503–504

mytime1.cpp, 507–508

mytime1.h, 506–507

mytime2.cpp, 512–514

mytime2.h, 512

N

(newline character), 40–41

n_chars() function, 288–290

name decoration, 370

named memory, 150

names, 61–62

aliases, 210–211, 432

array names, 160

functions, 454

header files, 37

name decoration, 370

name mangling, 370

reserved names, 1048–1049

source files, 21

symbolic names, 88–89

universal character names, 85–86

variables, 66–68

namespace keyword, 426–427

namespaces, 37–38, 424, 1137–1138

aliases, 432

creating, 426–427

declarative region, 424

example, 436–437

namesp.cpp, 434–435

namesp.h, 433–434

usenmsp.cpp, 435–436

global, 426

guidelines, 437

nesting, 431–432

open, 426

scope, 400, 424

std, 60

unnamed, 432–433

using declaration, 427–431

using directive, 428–431

navigating files, 1021–1029

nested classes, 611, 798–800

access control, 801

scope, 800–801

templates, 801–805

nested loops, 223–227

nested namespaces, 431–432

nested structures, 611

nested.cpp, 226, 804

new operator, 168–170, 399, 419–423, 599

bad_alloc exceptions, 827–829

constructors, 590–593, 607

dynamic arrays, 153–156

dynamic structures, 166–168

free store, 171

memory allocation, 150–152

placement new, 601–606

reference variables, 354

newline character ( ), 40–41

newstrct.cpp, 168

next_permutation() algorithm, 934, 1116, 1126

noboolalpha manipulator, 980

non-const objects, returning references to, 594

non-member functions, 885–889

non-type arguments (arrays), 756–758

nonexpressions for loops, 184

nonmodifying sequence operations

adjacent_find(), 1103–1105

count(), 1103–1105

count_if(), 1103, 1106

equal(), 1103, 1106

find(), 1103–1104

find_end(), 1103–1105

find_first_of(), 1103–1105

find_if(), 1103–1104

for_each(), 1103–1104

mismatch(), 1103, 1106

search(), 1104, 1107

search_n(), 1104, 1107

noshowbase manipulator, 980

noshowpoint manipulator, 980

noshowpos manipulator, 980

NOT operator (!), 244–247

not.cpp, 244–245

nouppercase manipulator, 980

nth_element() function, 1115, 1118

null characters, 114

null pointers, 152

num_test.cpp, 180

number base display, 967–969

number-reading loops, 259–262

numbers, 1041

ASCII character set, 1051–1056

Big Endian/Little Endian, 1044

binary numbers, 1043–1044

combining with strings, 124–125

decimal numbers, 1041

factorials, calculating, 185–187

floating-point numbers

advantages/disadvantages, 94

constants, 93

decimal-point notation, 89

double data type, 91–93

E notation, 90

float data type, 91–93

long double data type, 91–93

harmonic mean, 805

hexadecimal numbers, 1042–1044

integers

bool, 87–88

char, 79–87

choosing integer types, 75–76

climits header file, 71–72

constants, 76–79, 88–89

initializing, 72–73

int, 68–71

long, 68–71

short, 68–71

sizeof operator, 71–72

unsigned, 73–75

width of, 68

number-reading loops, 259–262

numeric operations, 1126–1127

accumulate() function, 1127

adjacent_difference() function, 1128

inner_product() function, 1127

partial_sum() function, 1128

octal numbers, 1041–1042

pointers, 150

pseudorandom numbers, 540

numstr.cpp, 124

O

object code, 19

Object-Oriented Analysis and Design, Second Edition, 1129

Object-Oriented Modeling and Design, 1130

object-oriented programming. See OOP

Object-Oriented Software Engineering: A Use Case Driven Approach, 1129

objects, 49, 450, 701–702. See also classes; containers

arrays, 483–486

declaring, 483

example, 484–486

initializing, 483

assignable, 905

associating with files, 265

base-class objects, accessing, 716

cerr, 456, 956

cin, 47–48, 956, 983–985

get() function, 122–123, 215–217, 220–223, 290, 993–994

getline() function, 120–121

loops, 214–215

operator overloading, 985–986

stream states, 987–991

class, 705

clog, 956

contained objects

compared to private inheritance, 720–721

initializing, 706–707

interfaces, 707–710

copy constructible, 905

cout, 39, 956–958

buffers, flushing, 964–965

concatenation, 48, 960–961

endl manipulator, 40

field width display, 969–970

fill characters, 970–971

floating-point display precision, 971–972

formatting data types, 965–967

integer values, displaying, 46

functions, 81–82, 961–964

newline character, 40–41

number base display, 967, 969

overloaded << operator, 958–959

printing trailing zeros/decimal points, 972–979

creating, 463

defined, 14, 38

as exceptions, 812–816

ifstream, 1005–1008

ofstream, 1004–1008

ostringstream, 1030–1032

passing by reference, 689

passing by value, 689

pointers, 596–601

reference variables, 355–358

returning, 593–595, 689–690

const objects, 593–596

non-const objects, 594

stream, 956–957

string, 869, 872

subobjects, 713

this pointer, 477–482

valarray, 940–946

vector, 878–889, 940–946

adding elements to, 881–882

past-the-end iterators, 880–881

removing ranges of, 881

shuffling elements in, 886

sorting, 886

vect1.cpp example, 879–880

vect2.cpp example, 882–885

vect3.cpp example, 887–889

oct manipulator, 968–969, 980

octal numbers, 1041–1042

ofstream objects, 265, 1004–1008

one definition rule, 418

one-dimensional arrays, 223

OOP (object-oriented programming), 446–447, 452, 1032. See also classes; objects

client/server model, 461

overview, 14–15

open namespaces, 426

open() function, 267–269, 871, 1008, 1011–1014

opening files, 1008, 1013–1014

operands, 95

operator functions, 503

operator*(), 512–515

operator+(), 506–510

operator+(), 1090

operator-(), 512–515

operator[](), 703, 1083, 1102

operators. See also overloading operators

alternative tokens, 1048

arithmetic operators, 95–96

addition (+), 506–510

associativity, 96–97

division (/), 97–98

modulus (%), 99–100

multiplication (*), 512–515

order of precedence, 96–97

subtraction (-), 512–515

assignment (=), 45, 577, 687, 691–693

combination assignment operators, 192–193

custom definitions, 578–579

enumerator values, 142–143

overloading, 584–590

potential problems, 578

strings, 126–127

structures, 136–137

when to use, 577

associativity

examples, 1057–1058

table of, 1058–1061

binary operators, 536, 1057

bitwise operators

alternative representations, 1067–1068

logical bitwise operators, 1065–1067

shift operators, 1063–1065

testing bit values, 1069

toggling, 1069

turning bits off, 1069

turning bits on, 1068

comma (,), 195–198

concatenation (+), 126–127

conditional (?:), 250–251

const_cast, 849–850

decrement (—), 189–192

delete, 152–153, 168–171, 354, 399, 419–420, 599

dereferencing (*), 145, 148–149, 160

dynamic_cast, 840–849

functor equivalents, 927–928

increment (++), 178, 189–192

left shift (<<), 518–524, 606

member dereferencing operators, 1070–1073

new, 168–170, 399, 419–423, 599

bad_alloc exceptions, 827–829

constructors, 590–593, 607

dynamic arrays, 153–156

dynamic structures, 166–168

free store, 171

memory allocation, 150–152

placement new, 601–606

reference variables, 354

operator functions, 503

operator*(), 512–515

operator+(), 506–510

operator-(), 512–515

operator<<(), 518–524

precedence

examples, 1057–1058

table of, 1058–1061

reference (&), 341–344

reinterpret_cast, 852

relational operators, 198–201

C-style strings, comparing, 201–204

equality operator (==), 199–201

string class strings, comparing, 204–205

table of, 198

scope resolution (::), 409, 453, 1138

sizeof, 71–72

static_cast, 851

type cast, 848–852

type info structure, 840

typeid, 840, 845–851

unary operators, 536–537, 1057

OR operators

bitwise OR (|), 1065–1066

logical OR (||), 238–239, 246–247

or.cpp, 239

ordering, 887

ostream class, 49, 955, 960–961

functions, 961–964

iterator template, 900–901

ostringstream class, 1030–1032

ourfunc.cpp, 55

out_of_bounds exception, 826

outfile.cpp, 266

output. See I/O

output iterators, 895

overload resolution, 382–383

best matches, 383–385

exact matches, 383–385

multiple arguments, 388

partial ordering rules, 385–387

overloading functions, 216, 365–367, 502

example, 367–369

function signatures, 365

name decoration, 370

overload resolution, 382–388

when to use, 370

overloading operators, 502–504

addition operator (+), 506–510

cin object input, 985–986

example, 503–506

mytime0.cpp, 504

mytime0.h, 503

usetime0.cpp, 505–506

left shift operator (<<), 518–524, 958–959

member versus nonmember functions, 524–525

multiplication operator (*), 512–515

operator functions, 503

operator*(), 512–515

operator+(), 506–510

operator-(), 512–515

operator<<(), 518–524

restrictions, 510–512

subtraction operator (-), 512–515

vector class, 525–527, 535, 539

adding vectors, 526

declaring, 527–529

displacement vectors, 526

implementation comments, 537

member functions, 529–533

multiple representations, 534

overloaded arithmetic operators, 535–536

overloading overloaded operators, 536–537

Random Walk sample program, 538–541

state members, 533–534

overloading templates, 374–376, 382–388

ownership, 876

P

pairs.cpp, 761–762

palindromes, 949

pam() function, 329

parameterized types, 370

parameters, 287

parameter lists, 33

templates, 768–770

type, 748

partial ordering rules, 385–387

partial_sort_copy() function, 1115, 1118

partial_sort() function, 1115, 1118

partial specializations, 764–765

partial_sum() function, 1128

partition() function, 1109, 1114

passing objects

by reference, 344–347, 689

structure addresses, 320–322

structures, 314–320

by value, 689

past-the-end iterators, 880–881

peek() member function, 999–1003

peeker.cpp, 1000

period (.), 232

permutations, 933

defined, 1125

next_permutation() function, 1116, 1126

prev_permutation() function, 1126

pf() function, 330

pipe character (|), 238–239, 246–247, 1065–1066

placement new operator, 420–423, 601–606

placenew1.cpp, 602–603

placenew2.cpp, 604–605

plus_one.cpp, 189

plus sign (+)

addition operator (+), 506–510

concatenation operator (+), 126–127

increment operator (++), 189–192

pointed-to values, 160

pointer arithmetic, 156–161

pointer.cpp, 146

pointers, 144, 294–295, 750. See also iterators

assigning values to, 160

auto_ptr, 873–877

C++ philosophy, 145

cautions, 149

compared to pointed-to values, 160

const keyword, 305–308

declaring, 146–149, 159

deferencing, 160

delete operator, 152–153

example, 144–145

function pointers, 327–329

increment/decrement operators, 191–192

inheritance, 660–662

initializing, 147–149

integers, 150

iterators, 899

member dereferencing operators, 1070–1073

new operator, 150–152

passing variables, 344–347

pointer arithmetic, 156–161

pointer notation, 161

pointers to objects, 596–601

pointers to pointers, 305–306

smart, 875

smart pointers, 877

stacks of pointers, 750–756

strings, 162–166

this, 477–482

polar coordinates, 316–317

converting rectangular coordinates to, 317–320

polymorphic public inheritance, 647–648

base-class functions, 695

Brass class

declaration, 648–651

implementation, 651–656

objects, 656–657

BrassPlus class

declaration, 648–651

implementation, 651–656

objects, 656–657

constructors, 665

dynamic binding, 660–663

pointer compatibility, 660–662

reference type compatibility, 660–662

static binding, 660–663

virtual destructors, 660, 665, 694

virtual functions, 662–665, 693–694

behavior, 657–659

friends, 666, 694

memory and execution speed, 664

redefinition, 666–667

virtual function tables, 663

pop_back() function, 1099

pop_front() function, 1099

pop() function, 751

pop_heap() function, 1116

popping values off heap, 1123

portability of C++, 17–19

postfixing, 191

potential scope, 424

pound sign (#), 214

pow() function, 54

precedence of operators

comma operator, 198

examples, 1057–1058

logical operators, 246–247

table of, 1058–1061

precise.cpp, 971

precision() function, 361, 971–972

predefined functors, 926–928

predicates

adaptable, 929–930

binary, 923, 926, 929–930

unary, 923, 926

prefixing, 191

preprocessors, 35–36

prev_permutation() function, 1126

print() functions, 365

printf() function, 31, 46

priority_queue class templates, 914

priority_queue containers, 914

private inheritance, 712–713

base-class components, initializing, 713–714

base-class friends, accessing, 716–718

base-class functions, accessing, 715–716

base-class objects, accessing, 716

compared to containment, 720–721

Student class example, 713, 718–720

private keyword, 451–453, 713

private member functions, 452–453

probability() function, 291–292

problem domains, 1032

procedural languages, 13

procedural programming, 446–447

procedures. See functions

programs. See applications

properties

algorithms, 932–933

class member functions, 695–696

containers, 906–907

reference variables, 347–349

protected classes, 668–669, 693

protected inheritance, 721–722

protected keyword, 668–669, 693, 721

protos.cpp, 283

prototypes (functions), 51–54, 283–285, 1136

pseudorandom numbers, 540

ptrstr.cpp, 162–163

public derivation, 636

public inheritance, 647–648, 721. See also multiple inheritance

base-class functions, 695

Brass class

declaration, 648–651

implementation, 651–656

objects, 656–657

BrassPlus class

declaration, 648–651

implementation, 651–656

objects, 656–657

constructors, 665

dynamic binding, 660–663

pointer compatibility, 660–662

reference type compatibility, 660–662

static binding, 660–663

virtual destructors, 660, 665, 694

virtual functions, 662–665, 693–694

behavior, 657–659

friends, 666, 694

memory and execution speed, 664

redefinition, 666–667

virtual function tables, 663

public interfaces, 449

public keyword, 451–453

public member functions, 452–453

pure virtual functions, 671

push_back() function, 881–882, 936, 1099

push_front() function, 1099

push_heap() function, 1116

pushing values onto heap, 1123

put() function, 961–964

putback() member function, 999–1003

Q

qualified names, 427, 454

qualifiers, cv-qualifiers, 415–417. See also keywords; statements

const, 416–418

volatile, 416

Queue class

class declaration, 618–621

design, 608–609

implementation, 609–612

functions, 612–618

public interface, 609

templates, 913–914

queue containers, 913–914

queue simulation, 607–608

bank.cpp simulation, 621–626

Customer class, 618–621

Queue class

class declaration, 618–621

design, 608–609

implementation, 609–612

functions, 612–618

public interface, 609

templates, 913–914

Queue() function, 612

queue.cpp, 619–621

queue.h, 619

queuecount() function, 614

queuetp.h, 802–803

quotation marks (”), 38

R

rand() function, 54, 540

random access (files), 1021–1029

random access iterators, 896–897

random_shuffle() function, 885–889, 1109, 1114

Random Walk sample program, 538–539

random.cpp, 1026–1029

randwalk.cpp, 538–539

range_error exception, 827

ranges (arrays), 303–304

RatedPlayer class, 636–638

header files, 641

function definitions, 641–642

RatedPlayer object, 642–643

Rating() function, 644

rbegin() function, 1077, 1097

rdstate() stream state function, 987–991

read() member function, 999–1003, 1018, 1021

reading

C-style strings

get(), 121–123

getline(), 120–121

string class strings, 129–131

text files, 268–273, 1005–1007

text with loops, 213

cin object, 214–215

cin.get() function, 215–217, 220–223

end-of-file conditions, 217–220

sentinel characters, 214

real numbers, 52

rect_to_polar() function, 318–319

rectangular coordinates, 316

converting to polar coordinates, 317–320

recur.cpp, 325

recurs() function, 324–326

recursion

multiple recursive calls, 326–327

recursive use of templates, 759–760

single recursive call, 324–326

redefining virtual functions, 666–667

redirection, 217, 957–958

refcube() function, 348–350

reference arguments, 349–351, 361–362

reference counting, 876

reference operator (&), 341–344

reference type, 1095

reference variables, 340–341

arguments, 361–362

class objects, 355–358

creating, 341–344

function parameters, 344–347

inheritance, 358–361, 660–662

initialization, 342

properties, 347–349

returning, 689–690

structures, 351–353

const keyword, 354–355

example, 351–353

return references, 353–354

reference, passing by, 314, 344–347, 689

refinement, 899

register keyword, 405, 416

reinterpret_cast operators, 852

relational operators, 198–201

C-style strings, comparing, 201–204

equality operator (==), 199, 201

functor equivalents, 927–928

string class strings, comparing, 204–205

table of, 198

relationships

has-a, 645, 703–705

is-a, 645–646, 691, 723

remodel() function, 875

remote_access() function, 412

remove() function, 1100, 1108, 1112

remove_copy() function, 1108, 1112

remove_copy_if() function, 1108, 1112

remove_if() function, 925, 1100, 1108, 1112

rend() function, 1077–1078, 1097

replace() function, 1092, 1108–1110, 1114

replace_copy() function, 1108, 1111

replace_copy_if() function, 1108, 1111

replace_if() function, 1108, 1111

report() function, 771

reserve() function, 870, 1083, 1099

reserved names, 1048–1049

reserved words, 1047–1049. See also keywords; statements

ResetRanking() function, 643

resize() function, 941, 1082, 1098

return addresses, 816

return statements, 32

return types (functions), 33

return values (functions), 50–51, 58–60

returning objects, 593–595

C-style strings, 312–313

const objects, 593–596

non-const objects, 594

structures, 314–320

reverse iterators, 901–903

reverse() function, 1078, 1100, 1108

reverse_copy() function, 1108, 1113

reversible containers

associative, 919–922

list, 910–913

vector, 910

rewrite rule, 457

rfind() function, 866, 1085

right manipulator, 980

right shift and assign operator (>>=), 1065

right shift operator (>>), 1064–1065

Ritchie, Dennis, 13

rotate_copy() function, 1109, 1114

rotate() function, 1109, 1114

RTTI (runtime type information), 839–840

incorrect usage, 847–848

operators

dynamic cast, 840–845

typeid, 840, 845–847, 850–851

type info class, 845–847, 850–851

type info structure, 840

rtti1.cpp, 842–843

rtti2.cpp, 845, 847

ruler.cpp, 326

runtime, 145. See also RTTI (runtime type information)

runtime_error exception, 826

runtime type information. See RTTI

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.131.10