A B C D E F G H I J-K L M N O P Q R S T U V W X-Z

Symbols

[top]

<=, 217

+ (addition operator), overloading, 569–572

-= (assignment operator), 212

*= (assignment operator), 212

+= (assignment operator), 211

%= (assignment operator), 212

/= (assignment operator), 212

= (assignment operator), 43–44, 644, 767–768, 772–775

compared to equality operator, 218–220

custom definitions, 645–646

enumerator values, setting, 152

overloading, 652–658

sayings1.cpp, 656

string1.cpp, 653–656

string1.h, 652–653

potential problems, 645

strings, 133–134

structures, 145–146

when to use, 644

& (bitwise AND operator), 1239–1240

~ (bitwise negation operator), 1237

| (bitwise OR operator), 1237–1238

^ (bitwise XOR operator), 1238

{} (braces), 258

[] (brackets), 649–651

, (comma operator), 214–217

example, 214–216

precedence, 217

/*...*/ comment notation, 33

// comment notation, 27, 32

+ (concatenation operator), strings, 133–134

?: (conditional operator), 273–274

- - (decrement operator), 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

* (dereferencing operator), 155–159

pointers, 171–172

/ (division operator), 100–101

== (equality operator), 217

compared to assignment operator, 218–220

++ (increment operator), 197, 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

!= (inequality operator), 217

&& (logical AND operator), 262

alternative representations, 270

example, 263–265

precedence, 269–270

ranges, 265–267

! (logical NOT operator), 267–269

alternative representations, 270

precedence, 269

|| (logical OR operator), 260–262

alternative representations, 270

example, 261–262

-]* (member dereferencing operator), 1243–1246

.* (member dereferencing operator), 1243–1246

% (modulus operator), 101–102

* (multiplication operator), overloading, 574–578

\n newline character, 38–39

< operator, 217

. (period), 255

# (pound sign), 234

“ (quotation marks), 36

& (reference operator), 383–386

]]= (right shift and assign operator), 1237

]]}(right shift operator), 1236

:: (scope resolution operator), 467, 514, 1332,

; (semicolon), 29–30

- (subtraction operator), overloading, 574–578

~ (tilde), 529

_ (underscore), 1222

A

[top]

ABCs (abstract base classes), 746–749

ABC philosophy, 756

AcctABC example, 749–751, 754–755

enforcing interface rules with, 757

abort() function, 897–898, 928–930

abstract data types (ADTs), 552

abstraction, 507. See also classes

access control, 892

access control (classes), 511–513

accessing

content of template and parameter packs, 1198–1199

strings, 1259

AcctABC class, 749–751, 754–755

acctabc.cpp, 751

acctabc.h, 750

accumulate() function, 1320

acquire() function, 516

actual arguments, 314

adaptable binary functions, 1035

adaptable binary predicate, 1035

adaptable functors, 1032

adaptable generators, 1035

adaptable predicate, 1035

adaptable unary functions, 1035

adapters, 1002

adding vectors, 590

addition operator (+), overloading, 569–572

addpntrs.cpp, 167

address.cpp, 154

addresses

addresses of functions, obtaining, 362

of arrays, 170

structure addresses, passing, 351–353

adjacent_difference() function, 1321–1322

adjacent_find() function, 1287, 1290

ADTs (abstract data types), 552–557

algorithms, 1035

copying, 1036

groups, 1035–1036

in-place, 1036

properties, 1036–1037

aliases

creating, 230

declarations, 1157

namespaces, 491

align.cpp, 1246

alignof() operator, 1204

allocating memory, 968

bad_alloc exceptions, 921

dynamic memory allocation, 757

derived class does use new, 758–760

derived class doesn’t use new, 757–758

example, 761–766

new operator, 160–162

allocators, 979

alternative tokens, table of, 1222

American National Standards Institute (ANSI), C++ standard, 16

American Standard Code for Information Interchange. See ASCII character set

ampersand (&), 1239–1240

logical AND operator (&&), 262

alternative representations, 270

example, 263–265

precedence, 269–270

ranges, 265–267

reference operator (&), 383–386

AND operators

bitwise AND (&), 1239–1240

logical AND (&&), 262

alternative representations, 270

example, 263–265

precedence, 269–270

ranges, 265–267

and.cpp, 263–264

angle brackets, 1162

anonymous unions, 150

ANSI (American National Standards Institute), C++ standard, 16

ANSI C Standard Input/Output, 1062

append() method, 1265

append.cpp, 1125

appending

data to files, 1125–1127

strings, 133–134, 1265–1266

applications. See also compilers

creating, 18–19

portability, 15, 17–18

ANSI/ISO standard, 16

limitations, 16

source code, 19

file extensions, 20

apply() method, 1046

Area() method, 748

args, 1198

argument lists, 30

arguments, 31

arrays, 322–325

C-style strings, 339–341

command-line, 1119–1120

default arguments, 409–412

formal/actual, 314

multiple, 314–320

n_chars() example, 314–317

probability() example, 318–320

parameters, 314

passing by reference, 386, 389–390

passing by value, 313–314

reference arguments, 392–394, 408–409

two-dimensional arrays, 337–339

type conversions, 106

arguments (functions), 49, 53

arith.cpp, 98

arithmetic, pointers, 167–172

arithmetic operators, 97–99

associativity, 99–100

division (/), 100–101

functor equivalents, 1031–1032

modulus (%), 101–102

order of precedence, 99–100

overloading

addition operator (+), 569–572

multiplication operator (*), 574–578, 600

subtraction operator (-), 574–578

vector class, 599–600

array notation, 173

array objects, 355

fill function, 357

versus arrays, 188–189

versus vector objects, 188–189

array template class, 187

ArrayDb class, 791

arraynew.cpp, 166

arrayone.cpp, 117

arrays

addresses, 170

array notation, 173

arrays of objects, 546–549

declaring, 546

example, 547–549

initializing, 546

as function arguments, 322–325

const keyword, 327–328

declaring, 116–119

defined, 77, 116

design decisions, 325–326

displaying contents of, 327–328

dynamic arrays, 172–173

creating, 164–165

sample program, 165–167

examples, 328–331

filling, 326–327

function idioms, 331

functions and, 320–321

indexes, 117

initializing, 117–120

in C++11, 120

modifying, 328

naming, 172

one-dimensional arrays, 244

pointer arithmetic, 167–172

pointers, 321–322

ranges, 332–334

static binding, 172

strings, 123–124

initializing, 121

structures, 147–148

subscripts, 117

templates, non-type arguments, 843–845

two-dimensional arrays, 244–249, 337–339

declaring, 244–246

initializing, 246–249

variable arrays, 1329

versus vector objects, 188–189

arraytp.h, 843–844

arrfun1.cpp, 321

arrfun2.cpp, 323

arrfun3.cpp, 328

arrfun4.cpp, 332

arrstruc.cpp, 147–148

ASCII character set, table of, 1225–1229

assert, 1204

assgn_st.cpp, 145

assign() method, 1266, 1278

assignable objects, 1008

assigning

strings, 1266

values to pointers, 171

values to variables, 43

variable values, 43

assignment

string class, 133–134

type conversions, 103–104

assignment methods, 1260

assignment operator (=), 43–44, 644, 767–768, 772–775

compared to equality operator, 218–220

custom definitions, 645–646

enumerator values, setting, 152

enumerators, value ranges, 153

overloading, 652–658

sayings1.cpp, 656

string1.cpp, 653–656

string1.h, 652–653

potential problems, 645

strings, 133–134

structures, 145–146

when to use, 644

assignment operators, combination assignment operators, 211–212

assignment statements, 43–44

assignments, 1172–1173

associative containers, 1018, 1026

methods, 1281–1284

multimap, 1023–1025

set, 1019–1022

associativity, arithmetic operators, 99–100

associativity of operators, 1231

examples, 1234

table of, 1232–1234

asterisk (*), dereferencing operator (*) 155, 159

pointers 171–172

at() method, 1259

atan() function, 348

atan2() function, 348

ATM queue simulation

bank.cpp simulation, 695

Customer class, 694

Queue class

class declaration, 691

public interface, 679

ATM queue simulation, 678

bank.cpp simulation, 694–698

Customer class, 690–691

Queue class

class declaration, 694

design, 679

implementation, 680–682

methods, 682–690

public interface, 680

auto, 370

declarations, 1155

auto declarations, 109

auto keyword, 472

auto ptr, 1158

auto.cpp, 456–457

automatic memory storage, 182

automatic sizing (strings), 966–967

automatic teller machine simulation. See ATM queue simulation

automatic type conversion. See type conversion

automatic variables, 182, 314, 453–457

example, 455–457

initializing, 458

stacks, 458–459

autoptr template, 1333

auto_ptr class, 969, 973–975

versus unique_ptr, 975–977

average() function, 800

B

[top]

back insert iterators, 1005–1007

bad() method, 296

bad() stream state method, 1098–1102

badbit stream state, 1097–1102

bad_alloc exceptions, 921

Balance() function, 731

bank.cpp, 695–697

bank.cpp simulation, 694–698

Base 10 notation, 1215

Base 16 notation, 1216

binary equivalents, 1217–1218

Base 2 notation, 1217

hexadecimal equivalents, 1217–1218

Base 8 notation, 1215–1216

base classes

ABCs (abstract base classes), 746–749

ABC philosophy, 756

AcctABC example, 749–751, 754–755

enforcing interface rules with, 757

components, initializing, 798–799

friends, accessing, 801–804

methods, accessing, 800–801

objects, accessing, 801

relationships with derived classes, 718–720

TableTennisPlayer example, 708–710

using declarations, 807–808

virtual, methods, 826

virtual base classes, 815–817

combining with nonvirtual base classes, 828

constructors, 817–818

dominance, 828–829

methods, 818–828

base-class functions, 777

begin() method, 981–984, 1251–1252, 1275

best matches, 432–434

bidirectional iterators, 998

Big Endian, 1218

bigstep.cpp, 205

binary files, 1127–1133

binary functions, 1027–1030

binary numbers, 1217

hexadecimal equivalents, 1217–1218

binary operators, 601, 1234

binary predicates, 1027, 1030

binary search operations

binary_search() function, 1304, 1310

equal_range() function, 1304, 1309

lower_bound() function, 1304, 1309

upper_bound() function, 1304, 1309

binary searching

binary_search() function, 1304, 1310

equal_range() function, 1304, 1309

lower_bound() function, 1304, 1309

upper_bound() function, 1304, 1309

binary.cpp, 1131

binary_search() function, 1304, 1310

binding

dynamic binding, 173, 737, 739–740

static binding, 172, 737, 740

bit fields, 148

bit values, represented by constants, 1085

bitmask data type, 1085

bits, 68–69

clearing, 1086

testing, 1241–1242

toggling, 1241

turning off, 1241

turning on, 1241

bitwise AND operator (&), 1239–1240

bitwise negation operator (~), 1237

bitwise operators, 1235

alternative representations, 1240

logical bitwise operators, 1237–1240

shift operators, 1235–1237

overloading, 581–587

testing bit values, 1241–1242

toggling, 1241

turning bits off, 1241

turning bits on, 1241

bitwise OR operator (|), 1237–1238

bitwise XOR operator (^), 1238

block scope, 454

block.cpp, 212

blocks, 212–214

body (function), 29

for loops, 196–197

bondini.cpp, 86

books, 1323–1324

bool data type, 90

boolalpha manipulator, 1090

Boost project, 1205–1207

bottom-up programming, 13, 331

bound template friend functions, 861–864

braces {}, 258

bracket notation, 649–651

brackets, angle brackets, 1162

branching statements

if, 254

bug prevention, 260

example, 255

syntax, 254

if else

example, 256–257

formatting, 257–258

if else if else construction, 258–260

syntax, 255

switch, 274

enumerators as labels, 278–280

example, 275–278

syntax, 275

Brass class

class declaration, 723–727, 730–733

virtual destructors, 737

virtual method behavior, 734–736

brass.cpp, 727

brass.h, 724

BrassPlus class

class declaration, 723–726

class implementation, 727, 730–731

class objects, 732–733

virtual destructors, 737

virtual method behavior, 734–736

break statement, 280–282

bucks() function, 53

buffers, 1063–1064, 1067

flushing, 1063

Build All option (compiler), 24

buildstr() function, 341

buy() function, 516

bytes, 69

C

[top]

C language

ANSI C, 17

classic C, 17

development history, 11

programming philosophy, 11–13

C++, Macintosh, 25

C++ FAQ Lite, 1325

C++ FAQs, Second Edition, 1323

The C++ Programming Language, Third Edition, 1324

The C++ Standard Library: A Tutorial and Reference, 1323–1324

C++ Templates: The Complete Guide, 1324

C++11

arrays, initializing, 120

auto declarations, 109

basic assignments, 1260

constructors

initialization list, 1258

Rvalue reference, 1256

container requirements, 1010

containers, unordered associative containers, 1283

exception specifications, 908

initializer_list template, 1051–1053

libraries, 1203

list initialization, 537

noexcept, 1248

range-based loops, 233–234

scoped enumerations, 551–552

STL, 1271

containers, 1271–1273

structure initialization, 144

template aliases, 866

C-style strings, 120–122

in arrays, 123–124

combining with numeric input, 130–131

concatenating, 122

empty lines, 130

failbits, 130

null characters, 121

passing as arguments, 339–341

pointers, 173–178

returning from functions, 341–343

string input, entering, 124–126

string input, reading with get(), 127–130

string input, reading with getline( ), 126–127

C-style strings, comparing, 220–223

call signatures, 1194

calling

class member functions, 523

constructors, 526–527

functions, 309–311

pointers, 363–364

calling functions, 30, 49

calling.cpp, 306

callme1() function, 636

callme2() function, 636

capacity() method, 966, 1251, 1279

caret (^), 1238

carrots.cpp, 41

case sensitivity, 27, 32

casting, 1330–1331

downcasting, 738

upcasting, 738

implicit upcasting, 807

casting data types, 606–610, 612

casting types, 107–109

catch keyword, 900

catching exceptions, 900, 916–917

CC compiler (UNIX), 21–22

cctype library, 270–273

cctypes.cpp, 271–272

cerr object, 1067

cfront translator, 21

char data type, 80–87, 1064

escape sequences, 84–87

signed char, 88–89

universal character names, 87–88

unsigned char, 88–89

wchar_t, 89

character strings, 36

characters

ASCII character set, table of, 1225–1229

fill, 1081–1082

chartype.cpp, 81

CHAR_BIT constant, 72

CHAR_MAX constant, 72

char_type type, 1250

check_it.cpp, 1096

cheers() function, 307–309

choices.cpp, 188

choosing integer types, 76–77

cin, cin.get() function, 235–237, 241–244

cin object, 1067, 1093–1095

get() function, 128–130

getline() function, 126–127

loops, 234–235

operator overloading, 1095–1097

stream states, 1097–1098

effects, 1100–1102

exceptions, 1099–1100

setting, 1098

cin statement, 46

cin.get() function, 235–237, 241–244, 317

cin.get() member function, 1103–1105

cin.get(ch) function, 317

cinexcp.cpp, 1099

cinfish.cpp, 283–284

cingolf.cpp, 285–286

class declaration, 511–513

class inheritance, private inheritance, 797

base-class components, initializing, 798–799

base-class friends, accessing, 801–804

base-class methods, accessing, 800–801

base-class objects, accessing, 801

compared to containment, 806

Student class example, 798, 804–805

class keyword, 831

class member functions, operator overloading, 587–588

class scope, 454, 514, 549–551

class templates, 830–837

arrays, non-type arguments, 843–845

complex, 1045

explicit instantiations, 850

explicit specializations, 850–851

friend classes, 858

bound template friend functions, 861–864

non-template friend functions, 858–861

unbound template friend functions, 864–865

implicit instantiations, 850

member templates, 854–855

parameters, 855–858

partial specializations, 851–852

pointers, stacks of pointers, 837–843

versatility, 845–846

default type parameters, 849

multiple type parameters, 847

recursive use, 846–847

classes, 47–48, 508, 520, 1159

ABCs (abstract base classes), 746–749

ABC philosophy, 756

AcctABC example, 749–751, 754–755

enforcing interface rules with, 757

abstraction, 507

access control, 511–513

AcctABC, 749–751, 754–755

ADTs (abstract data types), 552–557

array template class, 187

ArrayDb, 791

auto_ptr, 969, 973–975

bad_alloc, 921

base classes

components, initializing, 798–799

friends, accessing, 801–804

methods, accessing, 800–801

objects, accessing, 801

using declarations, 807–808

virtual base classes, 815–829

Brass

class declaration, 723–726

class implementation, 727, 730–731

class objects, 732–733

virtual destructors, 737

virtual method behavior, 734–736

BrassPlus

class declaration, 723–726

class implementation, 727, 730–731

class objects, 732–733

virtual destructors, 737

virtual method behavior, 734–736

class scope, 549–551

client files, 533–536

compared to structures, 514

constructors, 524, 538–539, 768

calling, 526–527

conversion, 769–770

copy constructors, 639–644, 767

declaring, 525–526

default constructors, 527–528, 638–639, 766–767

defining, 525–526

delegating, 1180–1181

inheriting, 1181–1183

new operator, 659–661, 677–678

converting class type, 677

Customer, 690–691, 694

data hiding, 511–513, 523

data types, 507–508

declarations, 509–511, 522

defaulted and deleted methods, 1179–1180

defined, 36, 47, 508

defining, 47

definition of, 13

derived classes, 405

destructors, 524, 528–529, 538–539, 768

encapsulation, 512, 523

exception, 917

explicit conversion operators, 1159–1160

friend classes, 578–580, 877, 880–883, 886–888

compared to class member functions, 886

templates, 858–865

Tv class example, 878–883

header files, 530

ifstream, 1116–1119

implementation files, 530

inheritance

assignment operators, 772–775

base classes, 708–710, 718–720

constructors, 713–715

derived classes, 711–712, 716–720

exceptions, 922–927

has-a relationships, 721

is-a relationships, 720–722, 772

multiple, 814, 826

what’s not inherited, 772

ios, 1065

iostream, 1065

ios_base, 1065

constants representing bit values, 1085

istream, 47, 1065

data types recognized, 1093–1095

input methods, 1109–1114

single-character input, 1102–1106

string input, 1106–1108

member functions

const member functions, 537

const objects, 662–665

constructors, 524–528, 538–539, 638–639, 659–661, 677–678

copy constructors, 639–644

definitions, 509, 514–516, 523

destructors, 528–529, 538–539

friend member functions, 883–886, 888–889

implicit member functions, 637–638

inline functions, 517–518

invoking, 523

non-const objects, 663

object membership, 518

objects, returning, 662–665

private, 513

properties, 777–778

public, 513

qualified names, 514

this pointer, 539–546

unqualified names, 514

member in-class initialization, 1160

nested classes, 682, 889–891

access control, 892

scope, 891–892

templates, 892–896

objects, 786–788

contained objects, 791–795

subobjects, 797

ofstream, 1115–1119

ostream, 47, 1065

ostringstream, 1142, 1144–1145

pointers, member dereferencing operators, 1242–1246

private inheritance

base-class components, initializing, 798–799

base-class friends, accessing, 801–802, 804

base-class methods, accessing, 800–801

base-class objects, accessing, 801

Student class example, 798

protected classes, 745–746, 775

Queue

class declaration, 691–694

design, 679

implementation, 680–682

methods, 682–690

public interface, 679–680

Sales

sales.cpp, 924

sales.h, 922

use_sales.cpp, 925–927

sample program, 518–520

special member functions, 1178–1179

Stack, 831–836

pointers, 837–843

static class members, 628–637

stdexcept exception classes, 918–920

Stock, 511

streambuf, 1065

string, 131–133, 353–354, 647, 952, 960, 965–966, 1333

appending, 133–134

assignment, 133–134

assignment operator, overloading, 652–658

automatic sizing, 966–967

bracket notation, 649–651

comparing, 960

comparison members, 648–649

complex operations, 135–136

concatenation, 133–134

constructors, 952–956

default constructor, 647–648

finding size of, 960

Hangman sample program, 962–965

input, 957–960

reading line by line, 136–140

searching, 960–961

static class member functions, 651–652

STL interface, 1038–1039

string comparisons, 223–224

structures, 144–145

StringBad, 628

constructors, 632–633

destructor, 633

strngbad.cpp, 630–631

strngbad.h, 628–629

vegnews.cpp sample program, 633–637

Student

contained objects interfaces, 792–795

contained objects, initializing, 791

design, 787–788

methods, 793–795

private inheritance, 798–805

sample program, 795–797

studentc.h, 789–790

TableTennisPlayer, 708

tabtenn0.cpp, 709

tabtenn0.h, 708

usett0.cpp, 710

this pointer, 539–546

Tv, 878–879, 883

tv.cpp, 880–882

tv.h, 879–880

tvfm.h, 885–886

use_tv.cpp, 882

type casts, 606–612

type conversions, 606–612

applying automatically, 616–618

conversion functions, 612–616

friends, 618–621

implicit conversion, 609

type info, 939–944

valarray, 786–787, 1045–1046, 1049–1051

vector, 120, 588–590, 600, 979–991, 1045–1046, 1049–1051

adding elements to, 982–983

adding vectors, 590

declaring, 591–592

displacement vectors, 589

implementation comments, 602

member functions, 592, 597

multiple representations, 599

overloaded arithmetic operators, 599–600

overloading overloaded operators, 601

past-the-end iterators, 981–982

Random Walk sample program, 602, 605–606

removing ranges of, 982

shuffling elements in, 987

sorting, 987

state members, 597–599

vect1.cpp example, 980–981

vect2.cpp sample program, 984–986

vect3.cpp sample program, 988–991

vector template class, 186–187

virtual methods

final, 1183–1184

override, 1183–1184

Worker, 810–814

classic C, 17

classifying data types, 97

clear() method, 1258, 1278, 1283

clear() stream state method, 1098–1102

clearing bits, 1086

client files, creating, 533–536

client/server model, 520

climits header file, 71–73

clock() function, 229

clog object, 1067

close() method, 292

code formatting, 39

source code style, 40

tokens, 39

white space, 39

code listings

acctabc.cpp, 751

acctabc.h, 750

addpntrs.cpp, 167

address.cpp, 154

align.cpp, 1246

and.cpp, 263–264

append.cpp, 1125

arith.cpp, 98

arraynew.cpp, 166

arrayone.cpp, 117

arraytp.h, 843–844

arrfun1.cpp, 321

arrfun2.cpp, 323

arrfun3.cpp, 328, 332

arrstruc.cpp, 147–148

assgn st.cpp, 145

auto.cpp, 456–457

bank.cpp, 695–697

bigstep.cpp, 205

binary.cpp, 1131

block.cpp, 212

bondini.cpp, 86

brass.cpp, 727

brass.h, 724

callable.cpp, 1192

calling.cpp, 306

carrots.cpp, 41

cctypes.cpp, 271–272

chartype.cpp, 81

check_it.cpp, 1096

choices.cpp, 188

cinexcp.cpp, 1099

cinfish.cpp, 283–284

cingolf.cpp, 285–286

compstr1.cpp, 221

compstr2.cpp, 223

condit.cpp, 273

constcast.cpp, 944

conversion functions, stone1.cpp, 616

convert.cpp, 57

coordin.h, 449–450

copyit.cpp, 1004

count.cpp, 1121

cubes.cpp, 390

defaults.cpp, 1077

delete.cpp, 181, 185

divide.cpp, 100

dma.cpp, 762–764

dma.h, 761–762

dowhile.cpp, 232

enum.cpp, 279

equal.cpp, 219

error1.cpp, 897–898

error2.cpp, 899

error3.cpp, 901

error4.cpp, 906–907

error5.cpp, 910, 913

exceed.cpp, 75

exceptions, newexcp.cpp, 920

exc_mean.cpp, 905–906

express.cpp, 200

external.cpp, 465

file1.cpp, 451

file2.cpp, 452

filefunc.cpp, 406–407

fileio.cpp, 1117

fill.cpp, 1082

firstref.cpp, 383

floatnum.cpp, 95

fltadd.cpp, 96

forloop.cpp, 196

formore.cpp, 203–204

forstr1.cpp, 206

forstr2.cpp, 215

fowl.cpp, 973

frnd2tmp.cpp, 860–861

fun ptr.cpp, 364, 368

funadap.cpp, 1034–1035

function overloading, leftover.cpp, 418

functions, tempover.cpp, 434–437

functions, arguments, twoarg.cpp, 316

functions, recursion, recur.cpp, 359

functor.cpp, 1028

funtemp.cpp, 420

getinfo.cpp, 45

get_fun.cpp, 1107

hangman.cpp, 962–965

hexoct2.cpp, 79

if/cpp, 255

ifelse.cpp, 257

ifelseif.cpp, 259

ilist.cpp, 1053

init ptr.cpp, 158

inline functions.cpp, 381

inserts.cpp, 1006

instr1.cpp, 125

instr2.cpp, 127

instr3.cpp, 129

iomanip.cpp, 1092

jump.cpp, 280–281

lambda0.cpp, 1186

lambda1.cpp, 1190

left.cpp, 410–411

leftover.cpp, 416–417

lexcast.cpp, 1206

limits.cpp, 70

list.cpp, 1015

listrmv.cpp, 1039–1040

lotto.cpp, 319

manip.cpp, 1079

manyfrnd.cpp, 865

memb_pt.cpp, 1244–1245

modulus.cpp, 102

morechar.cpp, 82

more_and.cpp, 266

multmap.cpp, 1024–1025

myfirst.cpp, 28

mytime0.h, 566

mytime1.cpp, 569–570

mytime1.h, 569

mytime2.cpp, 575

mytime2.h, 575

namesp.cpp, 493–494

namesp.h, 493

namespaces, static.cpp, 479

nested.cpp, 247, 895–896

newstrct.cpp, 179–180

not.cpp, 267–268

numstr.cpp, 130

num_test.cpp, 198

operator overloading

mytime0.cpp, 566

mytime3.cpp, 585

mytime3.h, 584

usetime0.cpp, 568

usetime3.cpp, 587

or.cpp, 261

ourfunc.cpp, 54

outfile.cpp, 290–291

pairs.cpp, 848

peeker.cpp, 1111

placenew1.cpp, 671–673

placenew2.cpp, 674–675

plus_one.cpp, 207

pointer.cpp, 155

precise.cpp, 1082

protos.cpp, 310

ptrstr.cpp, 174–175

queue.cpp, 692–694

queue.h, 691–692

queuetp.h, 893–895

random.cpp, 1138–1139

randwalk.cpp, 603

recur.cpp, 355, 358

reference variables as function parameters, swaps.cpp, 389

rtti1.cpp, 936–938

rtti2.cpp, 939–941

ruler.cpp, 360

rvref.cpp, 1163

sales.cpp, 924

sales.h, 922

sayings1.cpp, 656

sayings2.cpp, 665

secref.cpp, 385

setf.cpp, 1085

setf2.cpp, 1088

setops.cpp, 1021–1022

showpt.cpp, 1084

somedefs.h, 1192

sqrt.cpp, 51

stack.cpp, 554–555

stack.h, 553–554

stacker.cpp, 555–557

stacktem.cpp, 835–836

stacktp.h, 833–834

static.cpp, 470–471

stcktp1.cpp, 841–842

stcktp1.h, 839–840

stdmove.cpp, 1174

stock00.h, 510

stock1.cpp, 531

stock1.h, 530

stock2.cpp, 543

stock2.h, 543

stocks.cpp, class member functions, 515

stone1.cpp, 615

stone.cpp, 610

stonewt.cpp, 608

stonewt.h, 607

stonewt1.cpp, 614–615

stonewt1.h, 613

str1.cpp, 953

str2.cpp, 966–967, 971

strctfun.cpp, 348

strctptr.cpp, 352–353

strfile.cpp, 958–959

strgfun.cpp, 340

strgstl.cpp, 1038–1039

strin.cpp, 1144

string1.cpp, 653–656

string1.h, 653

strings, numeric input, numstr.cpp, 135

strings, returning, strgback.cpp, 341

strings.cpp, 123

strngbad.cpp, 630–631

strngbad.h, 629

strout.cpp, 1143

strquote.cpp, 402–403

strtref.cpp, 395

strtype1.cpp, 132

strtype2.cpp, 134

strtype4.cpp, 137

structur.cpp, 142

studentc.cpp, 793

studentc.h, 789–790

studenti.cpp, 802–803

studenti.h, 799

sumafile.cpp, 294–295

swaps.cpp, 387–388

switch.cpp, 276–277

tabtenn0.cpp, 709

tabtenn0.h, 708

tabtenn1.cpp, 717

tabtenn1.h, 716

tempmemb.cpp, 852

tempparm.cpp, 856–857

textin1.cpp, 234

textin2.cpp, 236

textin3.cpp, 239

textin4.cpp, 242

tmp2tmp.cpp, 862–864

topfive.cpp, 353

travel.cpp, 344–345

truncate.cpp, 1113

tv.cpp, 880–882

tv.h, 879–880

tvfm.h, 885–886

twoarg.cpp, 316

twod.cpp, 846–847

twofile1.cpp, 469

twofile2.cpp, 469

twoswap.cpp, 427–428

twotemps.cpp, 422

typecast.cpp, 108

use new.cpp, 161

usealgo.cpp, 1043–1044

usebrass1.cpp, 732–733

usebrass2.cpp, 734

usedma.cpp, 765

useless.cpp, 1165

usenmsp.cpp, 494–495

usesstok2.cpp, 547

usestok1.cpp, 533

usetime1.cpp, 571–572

usetime2.cpp, 577

usett0.cpp, 710

usett1.cpp, 717–718

use_sales.cpp, 925–927

use_stuc.cpp, 795–797

use_stui.cpp, 804–805

use_tv.cpp, 882

usestok0.cpp, 519

valvect.cpp, 1048

variadic1.cpp, 1199

vect.cpp, 593

vect.h, 591

vect1.cpp, 980

vect2.cpp, 984–985

vect3.cpp, 988

vegnews.cpp, 634

vslice.cpp, 1049–1050

waiting.cpp, 229

while.cpp, 225

width.cpp, 1080

Worker0.cpp, 811–812

Worker0.h, 810–811

workermi.cpp, 823–825

workermi.h, 821–822

workmi.cpp, 826–827

worktest.cpp, 813

write.cpp, 1073–1074

code style, 40

colon (), scope-resolution operator (::), 514

combination assignment operators, 211–212

comma operator, 214–217

example, 214–216

precedence, 217

command-line processing, 1119–1120

comments, 27, 33

/*...*/ notation, 33

// notation, 32

compare() method, 1264–1265

comparing

arrays, vector objects, and array objects, 188–189

strings, 960, 1263–1265

C-style strings, comparing, 220–223

string class strings, comparing, 223–224

comparison members (String class), 648–649

compile time, 155

compile time complexity, 1009–1010

compilers, 21

CC (UNIX), 21–22

definition of, 11

g++ (Linux), 22

gpp, 22

troubleshooting, 24

Windows, 23–24

compiling files separately, 447–449, 453

complex class template, 1045

composition, 785

compound statements (blocks), 212–214

compound types, 115–116

enumerations, 150–152

enumerators, 150–151

value ranges, 153

values, setting, 152

pointers, 153

assigning values to, 171

C++ philosophy, 155

cautions, 159

compared to pointed-to values, 172

declaring, 155–159, 171

deferencing, 171–172

delete operator, 163–164

example, 154

initializing, 157–159

integers, 160

new operator, 160–162

pointer arithmetic, 167–172

pointer notation, 173

pointers to objects, 665–670

strings, 173–178

structures, 140–142

arrays, 147–148

assignment, 145–146

bit fields, 148

dynamic structures, 178–180

example, 142–144

members, 141

string class members, 144–145

unions, 149

anonymous unions, 150

declaring, 149

compstr1.cpp, 221

compstr2.cpp, 223

concatenating strings, 122, 128, 1266

concatenating output, 46–47

concatenation

output, 1071–1072

string class, 133–134

concatenation operator (+), strings, 133–134

concepts

containers, 1007

container methods compared to functions, 1039–1041

properties, 1008–1010

sequence requirements, 1011–1012

functors, 1027–1030

iterators, models, 1000–1001

concurrent programming, 1202–1203

condit.cpp, 273

conditional operator (?::), 273–274

const, reference returns, 400

const keyword, 90–92, 473–474, 771–772

arrays, 327–328

pointers, 334–336

reference variables, 401

temporary variables, 392–394

const member functions, 537

const modifier as alternative to #define, 1327–1329

const objects, returning references to, 662–665

constant time, 1009

constant time complexity, 1009–1010

constants, 78–80. See also strings

char constants. See char data type

const keyword, 90–92

file modes, 1122–1123

floating-point constants, 96

representing bit values, 1085

size_type, 1251

symbolic constants, 72

symbolic names, 90–92

constcast.cpp, 944

constructors, 524, 742, 768

calling, 526–527

class, 524

conversion, 769–770

copy constructors, 639, 767

deep copying, 642–644

limitations, 640–642

shallow copying, 640

when to use, 639–640

declaring, 525–526

default constructors, 527–528, 638–639, 766–767

defining, 525–526

delegating, 1180–1181

inheritance, 713–715

initialization list, C++11, 1258

new operator, 659–661, 677–678

Rvalue reference, C++11, 1256

string class, 1253

constructors that use arrays, 1254

constructors that use n copies of character, 1257

constructors that use parts of arrays, 1254–1255

constructors that use ranges, 1257

copy constructors, 1255–1256

default constructors, 1254

String(), 647–648, 952–956

virtual base classes, 817–818

const_cast operator, 944

const_iterator type, 1273

const_reference type, 1273

contained objects

compared to private inheritance, 806

initializing, 791

interfaces, 792–795

container classes, 830

container concepts, 1007

container methods compared to functions, 1039–1041

properties, 1008–1010

sequence requirements, 1011–1012

container methods, compared to functions, 1039–1041

container requirements, C++11, 1010

container types

deque, 1013

list, 1014–1017

member functions, 1014–1016

priority_queue, 1017–1018

queue, 1017

stack, 1018

vector, 1012–1013

containers, 553

associative, 1018, 1026

multimap, 1023–1025

set, 1019–1022

C++11, unordered associative containers, 1283

deques, methods, 1278–1280

lists, methods, 1278–1280

maps, methods, 1281–1284

methods, 1275–1277

sets, methods, 1281–1284

stacks, 557

STL (Standard Template Library), 1161

C++11, 1271–1273

vectors, methods, 1278–1280

containment, 785

continue statement, 280–282

conversion constructors, 769–770

conversion operators, explicity, 1159–1160

convert.cpp, 57

converting

class type, 677

rectangular coordinates to polar coordinates, 348–351

to standard C++, 1327

autoptr template, 1333

C++ features, 1331

const instead of #define, 1327–1329

function prototypes, 1330

header files, 1331

inline instead of #define, 1329–1330

namespaces, 1331–1333

STL (Standard Template Library), 1334

string class, 1333

type casts, 1330–1331

converting data types, 102, 606–612

applying automatically, 616–618

conversion functions, 612–616

conversion in arguments, 106

conversion in expressions, 105–106

conversion on assignment, 103–104

friends, 618–621

implicit conversion, 609

type casts, 107–109, 606–612

coordin.h, 449–450

coordinates

converting, 348–351

polar coordinates, 347

rectangular coordinates, 346

copy constructable objects, 1008

copy constructors, 639, 767

deep copying, 642–644

limitations, 640–642

shallow copying, 640

when to use, 639–640

copy() function, 1293–1296

iterators, 1001–1002

copy() method, 1269

copying

deep copying, 642–644

shallow copying, 640

strings, 135, 1269

copying algorithms, 1036

copyit.cpp, 1004

copy_backward() function, 1294–1297

count() function, 862, 1042, 1287, 1291

count() method, 1283

count.cpp, 1121

count_if() function, 1287, 1291

counts() function, 862

cout object, 1067–1069

buffers, flushing, 1075–1076

concatenation, 1071–1072

field width display, 1080–1081

fill characters, 1081–1082

floating-point display precision, 1082–1083

formatting data types, 1076–1078

methods, 1071–1075

number base display, 1078–1079

printing trailing zeros/decimal points, 1083–1090

cout statement, 36

concatenated output, 46–47

cout.put() function, 83

endl manipulator, 37–38

integer values, displaying, 44–45

\n newline character, 38–39

cout.put() function, 83–84

covariance of return type, 744

cpp filename extension, 28

CRC cards, 1207

cstring header file, 123–124

ctime header file, 229

cube() function, 309, 312–313, 391

cubes.cpp, 390

cumulative totals, calculating, 1320

Customer class, 690–691, 694

cv-qualifiers, 472–473

const, 473–474

volatile, 473

c_in_str() function, 340–341

c_str() method, 1252

D

[top]

data hiding, 511–513, 523

data methods, 1251–1253

data objects, pointers, 161

data types, 507–508

ADTs (abstract data types), 552–557

aliases, creating, 230

bool, 90

classifying, 97

compound types, 116

double, 50

floating-point numbers, 92

advantages/disadvantages, 96–97

constants, 96

decimal-point notation, 92

double, 94–96

E notation, 92–93

float, 94–96

long double, 94–96

integers, 68

char, 80–89

choosing integer types, 76–77

climits header file, 71–73

constants, 78–80, 90–92

initializing, 73

int, 68–70

long, 68–70

short, 68–70

sizeof operator, 71–73

unsigned, 74–76

width of, 68

recognized by, 1093–1095

type casts, 606–612

type conversion, 606–612

applying automatically, 616–618

conversion functions, 612–616

friends, 618–621

implicit conversion, 609

type conversions, 102

conversion in arguments, 106

conversion in expressions, 105–106

conversion on assignment, 103–104

type casts, 107–109

data types, 140. See also compound types

Data() function, 820

data() method, 1251–1252

Dawes, Beman, 1205

dec manipulator, 1090–1091

dec manipulators, 1078–1079

decimal numbers, 1215

decimal points, trailing, 1083–1087, 1090

decision making, 253

declaration statements, 41–43

declaration-statement expressions, 202

declarations, 463

aliases, 1157

auto, 109, 1155

decltype, 1156

external, 143

return types, 1157

declarative region, 483

declaring

arrays, 116–119

arrays of objects, 546

classes, 509–513, 522

constructors, 525–526

function pointers, 362–363

example, 364

invoking functions with, 363–364

pointers, 155–159, 171

two-dimensional arrays, 244–246

unions, 149

variables, 41–43

static, 183

vector class, 591–592

decltype, 439

declarations, 1156

decorating names, 418

decrement operator (--), 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

deep copying, 642–644

default arguments, 409–412

default class constructors, 527–528

default constructors, 638–639, 766–767

default type template parameters, 849

defaulted methods, classes, 1179–1180

defaults.cpp, 1077

deferencing operator (*), pointers, 171–172

#define directive, converting to standard C++

const instead of #define, 1327–1329

inline instead of #define, 1329–1330

defining

class member functions, 514–516

classes, 47

constructors, 525–526

functions, 306–309

defining declarations, 463

definitions, 463

delegating constructors, 1180–1181

delete operator, 163–164, 180–183, 400, 454, 476–477, 668

delete.cpp, 181

deleted methods, classes, 1179–1180

deque class templates, 1013

deque containers, 1013

deques, methods, 1278–1280

dequeue() method, 689

dereferencing (*) operator, 155–159

dereferencing operators, 1242–1246

derived classes, 405

constructors, 713–715

creating, 711–712

header files, 716

method definitions, 716

objects, creating, 717–718

relationships with base classes, 718–720

derived types, 116

design

bottom-up, 13

top-down, 12

The Design and Evolution of C++, 775, 1324

destructors, 524, 528–529, 538–539, 768

class, 524

virtual destructors, 737, 742–743, 776

difference_type type, 1250, 1273

directives

#define, converting to standard C++, 1327–1330

#ifndef, 451

#include, 33

using, 35–36, 59–60, 487–490

displacement vectors, 589

divide-and-conquer strategy, 360–361

divide.cpp, 100

division operator (/), 100–101

dma.cpp, 762–764

dma.h, 761–762

do while loops, 231–233

dominance, virtual base classes, 828–829

double data type, 50, 94–96

double-ended queue, 1013

dowhile.cpp, 232

downcasting, 738

Draw() function, 818

dribble() function, 414

dynamic storage duration, 454

dynamic arrays, 172–173

creating, 164–165

new operator, 164

sample program, 165–167

dynamic binding, 164, 172–173, 737–740

dynamic cast operator, 934, 941–943

dynamic cast operators, 934–939

dynamic memory, 476–479, 482

dynamic memory allocation, 757

auto_ptr class, 969, 973–975

derived class does use new, 758–760

derived class doesn’t use new, 757–758

example, 761–766

dma.cpp, 762–764

dma.h, 761–762

usedma.cpp, 765

dynamic structures, creating, 178–180

dynamic_cast operator, 943

dynamic variables, 454

E

[top]

early binding, 737

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

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

empty lines in strings, 130

empty() method, 1258, 1275

encapsulation, 512, 523

end() method, 981–984, 1251, 1275

end-of-file conditions, 237–241

endl manipulator, 37–38

enqueue() function, 890

entry-condition loops, 198

enum statement, 278–280

enum variables, 150–152

enumerators, 150–151

value ranges, 153

values, setting, 152

enum.cpp, 279

enumerations, 150–152

enumerators, 150–151

scoped, 1158

C++11, 551–552

value ranges, 153

values, setting, 152

enumerators, 150–151

as labels, 278–280

EOF (end-of-file) conditions, 237–241

eof() function, 238

eof() method, 296

eof() stream state methods, 1097–1102

eofbit stream state, 1097–1102

equal sign (=)

assignment operator (=), 644, 767–768, 772–775

custom definitions, 645–646

enumerator values, setting, 152

overloading, 652–658

potential problems, 645

strings, 133–134

structures, 145–146

when to use, 644

equality operator (==), compared to assignment operator, 218–220

equal() function, 1288–1292

equal.cpp, 219

equality operator (==), 217

compared to assignment operator, 218–220

equal_range() function, 1024, 1304, 1309

equal_range() method, 1283, 1285–1286

erase() method, 982–984, 1267, 1278, 1282

erasing strings, 1267–1268

error codes, returning, 898–900

error handling. See handling exceptions

error1.cpp, 897–898

error2.cpp, 899

error3.cpp, 901

error4.cpp, 906–907

error5.cpp, 910, 913

escape sequences, 84–85

estimate() function, 362–364

eternal loops, 232

exact matches, 432–434

exceed.cpp, 75

exception class, 917

exception handlers, 900, 933

exception handling, 896–897, 900, 933

abort() function, 897–898

bad_alloc exceptions, 921

catching exceptions, 900, 916–917

cautions, 931–932

error codes, returning, 898–900

exception class, 917

exception handlers, 900

inheritance, 922–927

sales.cpp, 924

sales.h, 922

use_sales.cpp, 925–927

invalid_argument exceptions, 919

length_error exceptions, 919

logic_error exceptions, 918

objects as exceptions, 903–908

out_of_bounds exceptions, 919

range_error exceptions, 919

real-world note, 933

runtime_error exceptions, 919

stdexcept exception classes, 918–920

throwing exceptions, 900, 915–916

try blocks, 901–903

uncaught exceptions, 928–931

unexpected exceptions, 928–931

unwinding the stack, 909–910, 913–914

exception specifications, C++11, 908

exceptions, 1158

exceptions() stream state method, 1098–1102

exclamation point (!), logical NOT operator, 267–269

alternative representations, 270

precedence, 269

exc_mean.cpp, 905–906

executable code, 18

exit() function, 930

explicit, 1159–1160

explicit instantiations, 428–430, 850

explicit keyword, 610

explicit specializations, 425, 850–851

example, 426–428

third-generation specialization, 425–426

exporting, templates, 1162

express.cpp, 200

expression arguments, 844

expressions, 97, 200–202

combining with comma operator, 214

compared to statements, 201

conditional operator (?::), 273–274

declaration-statement expressions, 202

logical AND (&&), 262

alternative representations, 270

example, 263–265

precedence, 269–270

ranges, 265–267

logical NOT (!), 267–269

alternative representations, 270

precedence, 269

logical OR (||), 260–262

alternative representations, 270

example, 261–262

precedence, 269

relational operators, 217–218, 220

C-style strings, comparing, 220–223

equality operator (==), 218–220

string class strings, comparing, 223–224

table of, 217

sequence points, 208–209

side effects, 201, 208–209

type conversions, 105–106

extern keyword, 467–472

functions, 474

external declarations, 143

external linkage, 454

external variables, 463, 466–467

external.cpp, 465

ext_permutation() algorithm, 1038

F

[top]

factorials, calculating, 203–205

fail() method, 296, 1101

fail() stream state method, 1098–1102

failbit stream state, 1097–1102

failbits, 130

fields

bit fields, 148

width, 1080–1081

file extensions, 20

file I/O, 1114

checking stream states, 1118–1119

command-line processing, 1119–1120

file modes, 1122

appending data to files, 1125–1127

binary, 1127–1133

constants, 1122–1123

opening files, 1124–1125

text, 1129

files, random access, 1133–1142

opening multiple files, 1119

reading, 1116–1118

writing, 1115–1118

file scope, 454

file1.cpp, 451

file2.cpp, 452

filefunc.cpp, 406–407

fileio.cpp, 1117

files, 1129

associating objects with, 289

client files, creating, 533–536

climits, 71–73

compiling separately, 447–449, 453

cpp filename extension, 28

ctime, 229

EOF (end-of-file) conditions, 237–240

header filenames, 34

header files, 448–449

converting to standard C++, 1331

creating, 530

cstring, 123–124

managing, 451

implementation files, creating, 530

include files, 96

iostream, 33–34, 289, 1064, 1067

text files, 287–288

reading, 292–298

writing to, 288–292

file_it() function, 408

fill characters, 1081–1082

fill() function, 1081, 1294, 1299

array objects, 357

fill.cpp, 1082

filling arrays, 326–327

fill_array() function, 325–327, 331

fill_n() function, 1294, 1299

fin.clear() function, 1121

final, 1183–1184

find() function, 1287–1289

find() method, 960–961, 965, 1260–1261, 1283

finding, 1260

find_arr() function, 994

find_end() function, 1287–1290

find_first_not_of() method, 961, 1262–1263

find_first_of() function, 1287, 1290

find_first_of() method, 961, 1262

find_if() function, 1287–1289

find_last_not_of() method, 1263

find_last_of() method, 961, 1262

firstref.cpp, 383

fixed manipulator, 1091

flags, 1084

flags, setting, 1083

float data type, 94–96

floating points, display precision, 1082–1087, 1090

floating-point data types, default behavior, 1076

floating-point numbers, 92

advantages/disadvantages, 96–97

constants, 96

decimal-point notation, 92

double data type, 94–96

E notation, 92–93

float data type, 94–96

long double data type, 94–96

floatnum.cpp, 95

fltadd.cpp, 96

flush() function, 1076

flushing buffers, 1063

for loops

blocks, 212–214

body, 196–197

combination assignment operators, 211–212

comma operator, 214–217

example, 214–216

precedence, 217

compared to while loops, 227–228

decrement operator (--), 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

example, 196–197

expressions, 200–202

compared to statements, 201

declaration-statement expressions, 202

factorials, calculating, 203–205

increment operator (++), 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

initialization, 196–197

loop test, 196–197

loop updates, 196–198, 205–206

nested loops, 244–249

nonexpressions, 202

range-based, 1161

sequence points, 208–209

side effects, 201, 208–209

step size, 205–206

strings, 206–207

syntax, 197–199

for statements, declaration-statement expressions, 203

for-init-statement, 203

forcing moves, 1173–1174, 1177–1178

forever loops, 232

forloop.cpp, 196

formal arguments, 314

formatted input functions, 1094

formatting

if else statement, 257–258

incore, 1142–1145

source code, 39

source code style, 40

tokens, 39

white space, 39

with cout, 1076–1077

field width display, 1080–1081

fill characters, 1081–1082

floating-point display precision, 1082–1083

manipulators, 1090–1091

number base display, 1078–1079

trailing zeros/decimal points, 1083–1090

with iomanip header file manipulators, 1091

formore.cpp, 203–204

forstr1.cpp, 206

forstr2.cpp, 215

forward declaration, 884

forward iterators, 998

for_each() function, 987–988, 1287–1289

for_each() STL function, 991

fowl.cpp, 973

free memory storage, 182

free store, 454

free store (memory), 182–183

freeing memory, delete operator, 163–164

friend classes, 578–580, 877–888

base-class friends, accessing, 801–804

compared to class member functions, 886

templates, 858

bound template friend functions, 861–864

non-template friend functions, 858–861

unbound template friend functions, 864–865

Tv class example, 878–879, 883

tv.cpp, 880–882

tv.h, 879–880

tvfm.h, 885–886

use_tv.cpp, 882

friend functions, 578–580

creating, 579–580

type conversion, 618–621

friend keyword, 579–580

friend member functions, 578–580, 883

compared to friend classes, 886

example, 885–886

forward declaration, 884

shared friends, 888–889

frnd2tmp.cpp, 860–861

front insert iterators, 1005–1007

front() method, 1278

funadap.cpp, 1034–1035

function idioms, arrays, 331

function objects, 1026

function parameter packs, 1197–1198

unpacking, 1198–1199

function parameters, reference variables, 386–390

function pointers, 1184–1188

variations on, 365–370

function polymorphism, 412

function prototype scope, 454

function prototypes, 309–311, 1330

benefits, 312–313

C++ compared to ANSI C, 312

syntax, 311–312

function wrapper

fixing problems, 1194–1196

options for, 1196–1197

template inefficiences, 1191–1194

functional polymorphism, 564

functions, 18, 29, 48–49. See also names of specific functions

adaptable binary, 1035

adaptable unary, 1035

algorithms, 1035

groups, 1035–1036

properties, 1036–1037

arguments, 31, 49, 53

arrays, 322–325

multiple, 314–320

passing by value, 313–314

two-dimensional arrays, 337–339

arrays, 320–321

as arguments, 322–325

const keyword, 327–328

design decisions, 325–326

displaying contents of, 327–328

examples, 328–331

filling, 326–327

modifying, 328

pointers, 321–322

ranges, 332–334

two-dimensional arrays, 337–339

binary, 1027, 1030

body, 29

C-style strings

passing as arguments, 339–341

returning, 341–343

calling, 30, 49, 309, 311

case sensitivity, 27, 32

cin.get(), 317

cin.get(ch), 317

class member functions

const member functions, 537

constructors, 524–528, 538–539, 638–639, 659–661, 677–678

copy constructors, 639–644

definitions, 509, 514–516, 523

destructors, 528–529, 538–539

friend member functions, 883–889

implicit member functions, 637–638

inline functions, 517–518

invoking, 523

object membership, 518

private, 513

properties, 777–778

public, 513

qualified names, 514

this pointer, 539–546

unqualified names, 514

compared to container methods, 1039–1041

conversion functions, 677

defining, 306–309

definitions, 29

formatted input, 1094

friend functions, 578–580

creating, 579–580

type conversion, 618–621

function prototypes, 1330

headers, 29–31

inline functions, 379–382

compared to macros, 382

square(), 381–382

input, unformatted, 1102

lambda functions, 1184

language linking, 475–476

library functions, 52

linkage properties, 474–475

non-member, 986–988, 991

objects, returning, 662–664

const objects, 662–665

non-const objects, 663

operator overloading, 587–588

overloading, 237, 412–414, 564

example, 415–418

function signatures, 413

name decoration, 418

overload resolution, 431–438

when to use, 418

pf()364

pointers, 361–362

addresses of functions, obtaining, 362

const keyword, 334–336

declaring, 362–363

example, 364

invoking functions with, 363–364

pointers to pointers, 335

prototypes, 50–52

qualified names, 514

recursion, 357

multiple recursive calls, 359–361

single recursive call, 358–359

return addresses, 909

return types, 30

return values, 49

set_union(), 1020

signatures, 413

string class objects, 353–354

structures, 343–346

passing/returning, 344–351

polar coordinates, 347

rectangular coordinates, 346

structure addresses, passing, 351–353

templates, 419, 422

explicit instantiation, 428–430

explicit specializations, 425–428

implicit instantiation, 428–430

overload resolution, 431–438

overloading, 422–424

transform(), 1031

unary, 1027, 1030

unqualified names, 514

user-defined functions

example, 53–54

function form, 54–55

function headers, 55–56

return values, 57–59

using directive, 59–60

virtual functions, pure virtual functions, 748

void, 307

functor.cpp, 1028

functors, 1026–1027, 1184–1188

adaptable, 1032

concepts, 1027–1030

predefined, 1030–1032

equivalents for operators, 1032

funtemp.cpp, 420

fun_ptr.cpp, 364, 368

G

[top]

g++ compiler, 22

gcount() member function, 1109–1114

generate() function, 1294, 1299

generate_n() function, 1294, 1299

generators, 1027

generic programming, 14, 419, 951, 978, 992

associative containers, 1018–1026

multimap, 1023–1025

set, 1019–1022

container concepts, 1007

container methods compared to functions, 1039–1041

properties, 1008–1010

sequence requirements, 1011–1012

container types

deque, 1013

list, 1014–1017

priority_queue, 1017–1018

queue, 1017

stack, 1018

vector, 1012–1013

iterators, 992–997

back insert, 1005–1007

bidirectional, 998

concepts, 1000–1001

copy() function, 1001–1002

forward, 998

front insert, 1005–1007

hierarchy, 999–1000

importance of, 992–996

input, 997–998

insert, 1005–1007

istream iterator template, 1003

ostream iterator template, 1002–1003

output, 998

pointers, 1001

random access, 999

reverse, 1003–1005

types, 997

get() function, 127–130

get() function (cin), 235–237, 241–244

get() member function, 1102–1108

Get() method, 821

getinfo.cpp, 45

getline() function, 126–127, 957–960

getline() member function, 1106–1108

getline() method, 509, 1270

getname() function, 180–182

get_allocator() method, 1252

get_fun.cpp, 1107

global namespaces, 484

global scope, 454

global variables, compared to local variables, 467

good() method, 294

good() stream state method, 1097–1102

goodbit stream state, 1097–1102

gpp compiler, 22

greater than () operator, 217

greater than or equal to () operator, 217

H

[top]

handling exceptions, 896

hangman.cpp, 962–965

hardware, program portability, 16

harmonic mean, 896

harpo() function, 410

has-a relationships, 721, 788

header files, 448–449

climits, 71–73

converting to standard C++, 1331

creating, 530

cstring, 123–124

ctime, 229

iomanip, manipulators, 1091

iostream, 289

managing, 451

headers, filenames, 34

headers (function), 29–31, 55–56

heap operations

make_heap() function, 1305, 1314

pop_heap() function, 1305, 1314

push_heap() function, 1305, 1314

sort_heap() function, 1305, 1315

heaping

popping values off, 1314

pushing values onto, 1314

heaps

creating, 1314

defined, 1314

heap operations

make_heap() function, 1305, 1314

pop_heap() function, 1305, 1314

push_heap() function, 1305, 1314

sort_heap() function, 1305, 1315

sorting, 1315

heaps (memory), 182

hex manipulator, 1090–1091

hex manipulators, 1078–1079

hexadecimal numbers, 1216

binary equivalents, 1217–1218

hexoct2.cpp, 79

hierarchy, iterators, 999–1000

high-level languages, 11

history of C++, 10–15

C language

development history, 11

programming philosophy, 11–13

generic programming, 14

OOP, 13–14

hmean() function, 898–905

I

[top]

I/O (input/output), 1062, 1270

buffers, 1063–1067

redirecting, 1067–1068

streams, 1063–1067

text files, 287–288

reading, 292–298

writing to, 288–292

identifiers, special meanings, 1223

IDEs (integrated development environments), 19

if else statement, 255

example, 256–257

formatting, 257–258

if else if else construction, 258–260

syntax, 255

if statement, 254

bug prevention, 260

example, 255

syntax, 254

if.cpp, 255

ifelse.cpp, 257

ifelseif.cpp, 259

#ifndef directive, 451

ifstream objects, 1116–1119

ignore() member function, 1106–1108

ilist.cpp, 1053

imbuing, I/O with styles, 1077

implementation, changing, 521–522

implementation files, creating, 530

implicit conversion, 609

implicit instantiation, 428–430

implicit instantiations, 850

implicit keyword, 610

implicit member functions, 637–638

implicit upcasting, 807

in-class initialization, 1160

in-place algorithms, 1036

include (#include) directive, 33

include files, 96

includes() function, 1305, 1311

incore formatting, 1142–1145

increment operator (++), 197, 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

indeterminate values, 73

indexes, 117

indirect values, 155

inequality operator (!=), 217

inheritance

dynamic memory allocation, 757

derived class does use new, 758–760

derived class doesn’t use new, 757–758

example, 761–766

exceptions, 922–927

sales.cpp, 924

sales.h, 922

use_sales.cpp, 925–927

references, 405–408

inheritance (class), 708

ABCs (abstract base classes), 746–749

ABC philosophy, 756

AcctABC example, 749–755

enforcing interface rules with, 757

assignment operators, 772–775

base classes

relationships with derived classes, 718–720

TableTennisPlayer example, 708–710

Constructors, 713–715

derived classes

creating, 711–712

header files, 716

method definitions, 716

objects, creating, 717–718

relationships with base classes, 718–720

has-a relationships, 721

is-a relationships, 720–722, 772

multiple inheritance, 798, 808–830

virtual base classes, 815–829

Worker class example, 810–814

polymorphic public inheritance, 722–723

base-class functions, 777

Brass class declaration, 723–726

Brass class implementation, 727–731

Brass class objects, 732–733

BrassPlus class declaration, 723–726

BrassPlus class implementation, 727–731

BrassPlus class objects, 732–733

constructors, 742

dynamic binding, 737–740

pointer compatibility, 737–739

reference type compatibility, 737–739

static binding, 737–740

virtual destructors, 737, 742–743, 776

virtual functions, 734–736, 739–745, 775–776

private inheritance, 797

base-class components, initializing, 798–799

base-class friends, accessing, 801–804

base-class methods, accessing, 800–801

base-class objects, accessing, 801

compared to containment, 806

Student class example, 798–805

protected classes, 745–746, 775

protected inheritance, 806–807

public, 806

multiple, 826

what’s not inherited, 772

inheriting

constructors, 1181–1183

delegating, 1181–1183

initialization, 70

arrays, 117–120

arrays of objects, 546

automatic variables, 458

base-class components, 798–799

contained objects, 791

for loops, 196–197

pointers, 157–159

reference variables, 385

strings, 121

two-dimensional arrays, 246–249

initialization lists, 119

constructors, C++11, 1258

initializer_list, 1053–1054

uniform initialization, 1155

initializer_list template, C++11, 1051–1053

initializing

arrays, C++11, 120

variables, 52, 73

init_ptr.cpp, 158

inline functions, 379, 517–518

compared to macros, 382

square(), 381–382

inline modifier as alternative to #define, 1329–1330

inline qualifier, 517

inline.cpp, 381

inner_product() function, 1320–1321

inplace_merge() function, 1305, 1311

input, 46

cin object, 1093–1095

operator overloading, 1095–1097

stream states, 1097–1102

cin statement, 46

classes, string, 957–960

istream class, methods, 1109–1114

single-character, 1102–1106

strings, 1106–1108

input functions

formatted, 1094

unformatted, 1102

input iterators, 997–998

input/output, strings, 287, 1269–1270

insert iterators, 1005–1007

insert() method, 983–984, 1015–1016, 1267, 1277, 1282

inserting strings, 1267

inserts.cpp, 1006

instances, 511

instantiation, 832–836

instantiation

explicit, 428–430, 850

implicit, 428–430, 850

instr1.cpp, 125

instr2.cpp, 127

instr3.cpp, 129

int data type, 68–70

int main() function header, 30–31

integer values, displaying with cout, 44–45

integers, 68

bool, 90

char, 80–87

escape sequences, 84–87

signed char, 88–89

universal character names, 87–88

unsigned char, 88–89

wchar_t, 89

choosing integer types, 76–77

climits header file, 71–73

constants, 78–80

const keyword, 90–92

symbolic names, 90–92

initializing, 73

int, 68–70

long, 68–70

pointers, 160

short, 68–70

sizeof operator, 71–73

unsigned, 74–76

width of, 68

integrated development environments, 19

interfaces

contained objects, 792–795

defined, 509–510

public interfaces, 509

internal linkage, 454

internal manipulator, 1091

internal variables, 467–470

International Standards Organization (ISO), C++ standard, 16

Internet resources, 1325

INT_MAX constant, 72

INT_MIN constant, 72

invalid_argument exception, 919

invoking, 526

iomanip.cpp, 1092

ios class, 1065

iostream class, 1065

iostream file, 33–34, 1064, 1067

iostream header file, 289

ios_base class, 1065

constants representing bit values, 1085

is-a relationships, 720–722, 772, 808

isalnum() function, 272

isalpha() function, 272

isblank() function, 272

iscntrl() function, 272

isdigit() function, 272

isempty() function, 685

isfull() function, 685

isgraph() function, 272

islower() function, 272

ISO (International Standards Organization), C++ standard, 16

ISO 10646, 88

isprint() function, 272

ispunct() function, 272

isspace() function, 272, 1101

istream class, 47, 1065

data types recognized, 1093–1095

input

methods, 1109–1114

single-character, 1102–1106

strings, 1106–1108

istream iterator template, 1003

isupper() function, 272

isxdigit() function, 273

is_open() method, 294, 1118–1119, 1125–1127

iterator type, 1273

iterators, 981–982, 992, 997

back insert, 1005–1007

bidirectional, 998

concepts, models, 1000–1001

copy() function, 1001–1002

forward, 998

front insert, 1005–1007

hierarchy, 999–1000

importance of, 992–996

input, 997–998

insert, 1005–1007

istream iterator template, 1003

ostream iterator template, 1002–1003

output, 998

pointers, 1001

random access, 999

reverse, 1003–1005

types, 997

iter_swap() function, 1294

J–K

[top]

jump.cpp, 280–281

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

keywords, 56. See also statements

auto, 472

catch, 900

class, 831

const, 90–92, 473–474, 771–772, 1327–1329

arrays, 327–328

pointers, 334–336

reference variables, 401

temporary variables, 392–394

decltype, 439

explicit, 610

extern, 467–472

functions, 474

friend, 579–580

implicit, 610

inline, 517, 1329–1330

mutable, 472–473

namespace, 483–486

private, 511–513, 798

protected, 745–746, 775, 806

public, 511–513

register, 472

static, 183, 472

functions, 475

struct, 140

table of, 1221

template, 831

throw, 900

try, 901

typedef, 230

typename, 831

using, 486–490, 807–808, 1332

virtual, 742

volatile, 473

key_comp() method, 1282–1285

key_compare type, 1281–1284

key_type type, 1281–1284

L

[top]

labels, enumerators as, 278–280

lambda functions, 1184–1188

reasons for, 1188–1191

language divergence, 16

language linking, 475–476

languages, evolution of, 1205

Boost, 1205–1207

Technical Report, 1206

last in-first out (LIFO) stacks, 459

late binding, 737

layering, 785

leaks (memory), 183

Lee, Meng, 978

left manipulator, 1091

left shift operator (<), 1235

overloading, 581–587, 676

left() function, 409–410, 415–418

left.cpp, 410–411

leftover.cpp, 416–417

length() functions, 960

length() method, 1249–1251

length_error exception, 919

lessthanlessthan (left shift operator), overloading, 581–587, 676

lessthansignlessthansign (left shift operator), 1236

lessthansignlessthansignequalsign (left shift and assign) operator, 1236

lexicographical_compare() function, 1306, 1318

libraries, 18, 378

C++11, 1203

cctype, 270–273

multiple library linking, 453

STL (Standard Template Library), 1334

library functions, 52

LIFO (last in-first out) stacks, 459

limits.cpp, 70

linear time, 1009

linear time complexity, 1009–1010

linkage

external, 454

functions, 474–475

internal, 454

language linking, 475–476

static variables

external linkage, 463–467

internal linkage, 467–470

no linkage, 470–472

linked lists, 680

linking multiple libraries, 453

Linux, g++ compiler, 22

list class templates, 1014–1017

member functions, 1014–1016

list containers, 1014–1017

member functions, 1014–1016

list initialization, C++11, 537

list.cpp, 1015–1016

listrmv.cpp, 1039–1040

lists

linked lists, 680

methods, 1278–1280

literal operators, 1204

Little Endian, 1218

local scope, 454

variables, 455–457

local variables, 314–315

compared to global variables, 467

logical AND operator (&&), 262

alternative representations, 270

example, 263–265

precedence, 269–270

ranges, 265–267

logical bitwise operators, 1237–1240

logical NOT operator (!), 267–269

alternative representations, 270

precedence, 269

logical operators, 260

alternative representations, 270

AND (&&), 262

example, 263–265

precedence, 269–270

ranges, 265–267

functor equivalents, 1031–1032

NOT (!), 267–269

OR (||), 260–262

Example, 261–262

logical OR operator (||), 260–262

alternative representations, 270

example, 261–262

precedence, 269

logic_error exception, 918

long data type, 68–70

long double data type, 94–96

long long type, 1153

LONG_MAX constant, 72

LONG_MIN constant, 72

loops, 195

break statement, 280–282

continue statement, 280–282

do while, 231–233

entry-condition loops, 198

for loops

blocks, 212–214

body, 196–197

combination assignment operators, 211–212

comma operator, 214–217

compared to while loops, 227–228

decrement operator (—), 207–211

example, 196–197

expressions, 200–202

factorials, calculating, 203–205

increment operator (++), 207–211

initialization, 196–197

loop test, 196–197

loop updates, 196–198, 205–206

nonexpressions, 202

sequence points, 208–209

side effects, 201, 208–209

step size, 205–206

strings, 206–207

syntax, 197–199

forever loops, 232

nested loops, 244–249

number-reading loops, 283–286

range-based, C++11, 233–234

text input234, cin object, 234–235

cin.get() function, 235–237, 241–244

end-of-file conditions, 237–241

sentinel characters, 234

while loops, 224–227

compared to for loops, 227–228

example, 225–226

syntax, 224

time-delay loops, 229–230

lotto probabilities, calculating, 317–320

lotto.cpp, 319

low-level languages, 11

low-level programming, 1203–1204

lower_bound() function, 1024, 1304, 1309

lower_bound() method, 1021, 1283

lvalue reference, 1162

M

[top]

machine language, definition of, 18

Macintosh, C++, 25

macros, compared to inline functions, 382

magval() method, 602

main() function, 29–30

calling, 30

importance of, 32

int main() header, 30–31

make_heap() function, 1305, 1314

malloc() function, 160

mangling names, 418

manip.cpp, 1079

manipulators, 38, 1090–1091

endl, 37–38

iomanip header file, 1091

number base display, 1078–1079

mantissas, 93

manyfrnd.cpp, 865

mapped_type type, 1281, 1284

maps, methods, 1281–1284

math operators, 97. See also arithmetic operators

max() function, 1305, 1316

max() method, 787, 1046

maxsize() method, 1275

max_element() function, 1305, 1317

max_size() method, 1251

mean, harmonic, 896

means() function, 909–914

member dereferencing operators, 1242–1246

member functions. See also constructors

const member functions, 537

constructors, 524, 538–539

calling, 526–527

declaring, 525–526

default constructors, 527–528, 638–639

defining, 525–526

new operator, 659–661, 677–678

copy constructors, 639

deep copying, 642–644

limitations, 640–642

shallow copying, 640

when to use, 639–640

definitions, 509, 514, 516, 523

destructors, 528–529, 538–539

friend member functions, 578–580, 883

compared to friend classes, 886

example, 885–886

forward declaration, 884

shared friends, 888–889

implicit member functions, 637–638

inline functions, 517–518

invoking, 523

object membership, 518

objects, returning, 662–664

const objects, 662–665

non-const objects, 663

private, 513

properties, 777–778

public, 513

qualified names, 514

template classes, list, 1014–1016

this pointer, 539–546

unqualified names, 514

member in-class initialization, 1160

member initializer lists, 683, 715

member templates, 854–855

members, structures, 141

memberwise assignment, 145

memberwise copying, 640

memb_pt.cpp, 1244–1245

memory. See also buffers

allocating

bad_alloc exceptions, 921

new operator, 160–162

automatic storage, 182

cv-qualifiers, 472–474

dynamic, 476–482

dynamic memory allocation, 757

derived class does use new, 758–760

derived class doesn’t use new, 757–758

example, 761–766

free store, 182–183

freezing delete operator, 163–164

function linkage, 474–475

language linking, 475–476

leaks, 183

memory-related methods, 1258

multifile programs, compiling separately, 447–453

named, 160

stack, 458–459

unwinding, 909–914

static storage, 183

storage class specifiers, 472–473

storage duration, 453–454

automatic variables, 455–459

scope and linkage, 454

static variables, 459–463, 466–472

storage methods, 182

memory allocation, dynamic (auto_ptr class), 969, 973–975

memory leaks, 163

merge() function, 1305, 1310–1311

merge() method, 1016–1017, 1280

merging

inplace_merge() function, 1305, 1311

merge() function, 1305, 1310–1311

methods. See also specific methods

base-class methods, accessing, 800–801

defaulted and deleted methods, classes, 1179–1180

end(), 984

inheritance, multiple, 826

insert(), 1015–1016

STL, 1161

virtual base classes, 818–828

MI (multiple inheritance), 798

min() function, 1305, 1316

min() method, 787, 1046

minimum values

finding 1316–1317

minus sign (-), decrement operator (—), 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

min_element() function, 1305, 1317

mismatch() function, 1288, 1291

mixtypes.cpp, 185

models, concepts of iterators, 1000–1001

modifiers

const, as alternative to #define, 1327–1329

inline, as alternative to #define, 1329–1330

modulus operator (%), 101–102

modulus.cpp, 102

morechar.cpp, 82

more_and.cpp, 266

move assignment operator, 1173

move constructors, 1165

move semantics, 1164–1171

observations, 1171–1172

Move() method, 748

moves, forcing, 1173–1178

MS-DOS, gpp compiler, 22

multifile programs, compiling separately, 447–453

multimap associative containers, 1023–1025

multiple arguments, 314–320

n_chars() example, 314–317

probability() example, 318–320

multiple class representations, 599

multiple inheritance, 798, 808–809, 829–830

virtual base classes, 815–817

combining with nonvirtual base classes, 828

constructors, 817–818

dominance, 828–829

methods, 818–828

Worker class example, 810–814

multiple library linking, 453

multiple public inheritance, methods, 826

multiple type parameters, 847

multiplication operator (*), overloading, 574–578

multisets, set operations

includes() function, 1311

set_difference() function, 1313

set_intersection() function, 1312

set_union() function, 1312

multmap.cpp, 1024–1025

mutable keyword, 472–473

mutating sequence operations

copy() function, 1293–1296

copy_backward() function, 1294–1297

fill() function, 1294, 1299

fill_n() function, 1294, 1299

generate() function, 1294, 1299

generate_n() function, 1294, 1299

iter_swap() function, 1294

partition() function, 1295, 1302–1303

random_shuffle() function, 1295, 1302

remove() function, 1295, 1299

remove_copy() function, 1295, 1300

remove_copy_if() function, 1295, 1300

remove_if() function, 1295, 1300

replace() function, 1294, 1298, 1302

replace_copy() function, 1294, 1298

replace_copy_if() function, 1294, 1298

replace_if() function, 1294, 1298

reverse() function, 1295

reverse_copy() function, 1295, 1301

rotate() function, 1295, 1301

rotate_copy() function, 1295, 1302

stable_partition() function, 1295, 1303

swap() function, 1294, 1297

swap_ranges() function, 1294, 1297

transform() function, 1294, 1297

unique() function, 1295, 1300

unique_copy() function, 1295, 1301

myfirst.cpp program, 27–29

comments, 32–33

header filenames, 34

iostream file, 33–34

main() function, 29–30

calling, 30

importance of, 32

int main() header, 30–31

namespaces, 35–36

output, displaying with cout, 36

endl manipulator, 37–38

\n newline character, 38–39

source code formatting, 39

source code style, 40

tokens, 39

white space, 39

mytime0.h, 566

mytime1.cpp, 569–570

mytime1.h, 569

mytime2.cpp, 575

mytime2.h, 575

N

[top]

name decoration, 418

name mangling, 418

named memory, 160

names

aliases, creating, 230

array names, 172

function qualified names, 514

function unqualified names, 514

name decoration, 418

namespace aliases, 491

reserved names, 1222–1223

namesp.cpp, 493–494

namesp.h, 493

namespace keyword, 483–486

namespace scope, 454

namespaces, 35–36, 482–483, 1331–1333

aliases, 491

creating, 483–486

declarative region, 483

example, 492–496

namesp.cpp, 493–494

namesp.h, 493

usenmsp.cpp, 494–495

global, 484

guidelines, 496–497

nesting, 490–491

open, 485

potential scope, 483

std, 59

unnamed, 491–492

using declaration, 486–490

using directive, 487–490

using-declaration, 491

using-directive, 491

naming conventions, 60

header files, 34

source files, 20

symbolic names, 90–92

universal character names, 87–88

variables, 66–68

narrowing uniform initialization, 1154

navigating files, 133–1141

temporary files, 1141–1142

nested classes, 682, 889–891

access control, 892

scope, 891–892

templates, 892–896

nested loops, 244–249

nested structures, 682

nested.cpp, 247, 895–896

nesting namespaces, 490–491

new, 921

new operator, 180–182, 454, 476–479, 482, 668

bad_alloc exceptions, 921

constructors, 659–661, 677–678

dynamic arrays, 164–167

dynamic structures, 178–180

free store, 183

memory allocation, 160–162

placement new, 671–676

reference variables, 400

newline character (\n), 38–39

newstrct.cpp, 179–180

next_permutation() algorithm, 1039

next_permutation() function, 1306, 1319

noboolalpha manipulator, 1090

noexcept, C++11, 1248

non-const objects, returning references to, 663

non-member functions, 986–991

non-type arguents (arrays), 843–845

nonexpressions, for loops, 202

nonmodifying sequence operations, 1286

adjacent_find() function, 1287, 1290

count() function, 1287, 1291

count_if() function, 1287, 1291

equal() function, 1288, 1291–1292

find() function, 1287–1289

find_end() function, 1287–1290

find_first_of() function, 1287, 1290

find_if() function, 1287–1289

for_each() function, 1287–1289

mismatch() function, 1288, 1291

search() function, 1288, 1292–1293

search_n() function, 1288, 1293

noshowbase manipulator, 1090

noshowpoint manipulator, 1091

noshowpos manipulator, 1091

NOT operators, logical NOT (!), 267–269

alternative representations, 270

precedence, 269

not.cpp, 267–268

nouppercase manipulator, 1091

nth_element() function, 1304, 1308, 1315

null characters, 121

null pointers, 163

nullptr, 1158

number base display, 1078–1079

number-reading loops, 283–286

numbers, 1215

ASCII character set, table of, 1225–1229

Big Endian/Little Endian, 1218

binary numbers, 1217

hexadecimal equivalents, 1217–1218

decimal numbers, 1215

factorials, calculating, 203–205

floating-point numbers, 92

advantages/disadvantages, 96–97

constants, 96

decimal-point notation, 92

double data type, 94–96

E notation, 92–93

float data type, 94–96

long double data type, 94–96

harmonic mean, 896

hexadecimal numbers, 1216

binary equivalents, 1217–1218

integers, 68

bool, 90

char, 80–89

choosing integer types, 76–77

climits header file, 71–73

constants, 78–80, 90–92

initializing, 73

int, 68–70

long, 68–70

short, 68–70

sizeof operator, 71–73

unsigned, 74–76

width of, 68

number-reading loops, 283–286

octal numbers, 1215–1216

pointers, 160

pseudorandom numbers, 605

numeric operations, 1319–1320

accumulate() function, 1320

adjacent_difference() function, 1321–1322

inner_product() function, 1320–1321

partial_sum() function, 1321

numstr.cpp, 130

num_test.cpp, 198

n_chars() function, 314–317

O

[top]

object code, definition of, 18

object types, 47

Object-Oriented Analysis and Design, Second Edition, 1323

object-oriented programming. See OOP (object-oriented programming)

objects, 511, 786

arrays, 355, 546–549

declaring, 546

example, 547–549

fill function, 357

initializing, 546

as exceptions, 903–908

assignable, 1008

associating with files, 289

base-class objects, accessing, 801

cerr, 1067

cin, 1067, 1093–1095

cin.get() function, 235–237, 241–244

get() function, 128–130

getline() function, 126–127

loops, 234–235

operator overloading, 1095–1097

stream states, 1097–1102

class, 788

clog, 1067

contained objects

compared to private inheritance, 806

initializing, 791

interfaces, 792–795

copy constructable, 1008

cout, 1067–1069

concatenation, 1071–1072

field width display, 1080–1081

fill characters, 1081–1082

floating-point display precision, 1082–1083

flushing buffers, 1075–1076

formatting data types, 1076–1078

methods, 1071–1075

number base display, 1078–1079

printing trailing zeros/decimal points, 1083–1090

creating, 523

defined, 13, 36

functions. See function objects

ifstream, 1116–1119

ofstream, 1115–1119

ostringstream, 1142–1145

passing by reference, 770

passing by value, 770

pointers, 665–670

reference variables, 401–405

returning, 662–664, 770–771

const objects, 662–665

non-const objects, 663

stream, 1067

string, 965

subobjects, 797

this pointer, 539–546

valarray, 1045–1051

vector, 979–991, 1045–1051

adding elements to, 982–983

past-the-end iterators, 981–982

removing ranges of, 982

shuffling elements in, 987

sorting, 987

vect1.cpp example, 980–981

vect2.cpp sample program, 984–986

vect3.cpp sample program, 988–991

oct manipulators, 1078–1079, 1090–1091

octal numbers, 1215–1216

ofstream objects, 290, 1115–1119

one definition rule, 475

one-dimensional arrays, 244

OOP (object-oriented programming), 13, 506–507, 512, 1207

classes, 47–48

client/server model, 520

overview, 13–14

open namespaces, 485

open() method, 291–293, 967, 1119, 1122–1125

opening files, 1124–1125

multiple, 1119

operands, 97

operator functions, 565

operator overloading, 37, 564–566

addition operator (+), 569–572

cin object input, 1095–1097

example, 565–569

mytime0.cpp, 566

mytime0.h, 566

usetime0.cpp, 568–569

left shift operator (<), 581–587

member versus nonmember functions, 587–588

multiplication operator (*), 574–578

operator functions, 565

operator*(), 574–578

operator+(), 569–572

operator-(), 574–578

operator<<(), 581–585, 587

restrictions, 573–574

subtraction operator (-), 574–578

vector class, 588–590, 600

adding vectors, 590

declaring, 591–592

displacement vectors, 589

implementation comments, 602

member functions, 592, 597

multiple representations, 599

overloaded arithmetic operators, 599–600

overloading overloaded operators, 601

Random Walk sample program, 602, 605–606

state members, 597–599

with classes, string, 965

operator*() function, 574–578

operator+() function, 569–572

operator+() method, 1266

operator-() function, 574–578

operators, 1235

addition operator (+), overloading, 569–572

alternative tokens, 1222

arithmetic operators, 97–99

associativity, 99–100

division (/), 100–101

modulus (%), 101–102

order of precedence, 99–100

assignment (=), 43–44, 644, 767–768, 772–775

custom definitions, 645–646

enumerator value ranges, 153

enumerator values, setting, 152

overloading, 652–658

potental problems, 645

strings, 133–134

structures, 145–146

when to use, 644

associativity, 1231

examples, 1234

table of, 1232–1234

binary operators, 601, 1234

bitwise operators, 1235

alternative representations, 1240

logical bitwise operators, 1237–1240

shift operators, 1235–1237

testing bit values, 1241–1242

toggling, 1241

turning bits off, 1241

turning bits on, 1241

combination assignment operators, 211–212

comma, 214–217

example, 214–216

precedence, 217

concatenation (+), strings, 133–134

conditional (?::), 273–274

const_cast, 944

decrement (—), 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

deferencing (*), pointers, 171–172

defined, 70

delete, 163–164, 180–183, 400, 454, 476–477, 668

dereferencing (*), 155–159

dynamic cast, 934–943

functor equivalents for arithmetic, logical, and relational operators, 1031–1032

increment (++), 197, 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

left shift operator (<<)

overloading, 581–587, 676

literal operators, 1204

member dereferencing operators, 1242–1246

multiplication operator (*), overloading, 574–578

new, 180–182, 454, 476–482, 668

bad_alloc exceptions, 921

constructors, 659–661, 677–678

dynamic arrays, 164–167

dynamic structures, 178–180

free store, 183

memory allocation, 160–162

placement new, 671–676

reference variables, 400

operator functions, 565

operator*(), 574–578

operator+(), 569–572

operator-(), 574–578

operator<<(), 581–587

overloading, 101, 564–565

addition operator (+), 569–572

assignment operator, 652–658

example, 565–569

left shift operator (<<), 581–587, 676

member versus nonmember functions, 587–588

multiplication operator (*), 574–578

operator functions, 565

overloading overloaded operators, 601

restrictions, 573–574

subtraction operator (-), 574–578

precedence, 1231

examples, 1234

table of, 1232–1234

reference operator (&), 383–386

reinterpret_cast, 946

relational operators, 217–220

C-style strings, comparing, 220–223

equality operator (==), 218–220

string class strings, comparing, 223–224

table of, 217

scope resolution (::), 467

scope-resolution (::), 514

scope-resolution operator, 1332

sizeof, 71–73

static_cast, 945–946

subtraction operator (-), overloading, 574–578

type cast, 943–944

type info structure, 934

typeid, 934, 939–944

unary minus, 601

unary operators, 601, 1234

operator[]() method, 787, 1259, 1283–1286

OR operators

bitwise OR (|), 1237–1238

logical OR (||), 260–262

alternative representations, 270

example, 261–262

precedence, 269

or.cpp, 261

ordering

strict weak, 988

total, 988

ostream class, 47, 1065

ostream iterator template, 1002–1003

ostream methods, 1071–1075

ostringstream class, 1142–1145

ourfunc.cpp, 54

outfile.cpp, 290–291

output

buffers, flushing, 1075–1076

classes, ostream, 1070–1075

concatenating, 46–47, 1071–1072

cout

field width display, 1080–1081

fill characters, 1081–1082

floating-point display precision, 1082–1083

formatting data types, 1076–1078

number base display, 1078–1079

printing trailing zeros/decimal points, 1083–1090

cout object, 1069

displaying with cout, 36

concatenated output, 46–47

endl manipulator, 37–38

integer values, 44–45

\n newline character, 38–39

output iterators, 998

out_of_bounds exception, 919

overload resolution, 431–432

best matches, 432–434

exact matches, 432–434

multiple arguments, 438

partial ordering rules, 434–436

overloading

functions, 237, 412–414, 564

example, 415–418

function signatures, 413

name decoration, 418

overload resolution, 431–438

when to use, 418

operators, 101, 564–565

addition operator (+), 569–572

assignment operator, 652–658

example, 565–569

left shift operator (<<), 581–587, 676

member versus nonmember functions, 587–588

multiplication operator (*), 574–578

operator functions, 565

restrictions, 573–574

subtraction operator (-), 574–578

vector class, 588–590

reference parameters, 415

templates, 422–424

overload resolution, 431–438

override, 1183–1184

ownership, 973

P

[top]

pairs.cpp, 848

palindromes, 1057

pam() function, 362–363

parameter lists, 30

parameterized types, 419

parameters, 314

templates, 855–858

type, 834

partial ordering rules, 434–436

partial specializations, 851–852

partial_sort() function, 1304, 1307

partial_sort_copy() function, 1304, 1307–1308

partial_sum() function, 1321

partition() function, 1295, 1302–1303

passing

structure addresses, 351–353

structures, 344–351

passing by reference, 386, 389–390

passing objects

by reference, 770

by value, 770

past-the-end iterators, 981–982

peek() member function, 1109–1114

peeker.cpp, 1111

period (.), 255

permutations, 1038

defined, 1318

functions

next_permutation(), 1306, 1319

prev_permutation(), 1319

pf() function, 364

pipe character (|), 1237–1238

logical OR operator (||), 260–262

alternative representations, 270

example, 261–262

precedence, 269

placement new operator, 478–482, 671–676

placenew1.cpp, 671–673

placenew2.cpp, 674–675

plus sign (+)

addition operator (+), overloading, 569–572

concatenation operator (+), strings, 133–134

increment operator (++), 207–208

pointers, 210–211

postfixing, 209–210

prefixing, 209–210

plus_one.cpp, 207

pointed-to values, 172

pointer arithmetic, 167–172

pointer.cpp, 155

pointers, 153, 321–322, 837

assigning values to, 171

auto_ptr, 969, 973–975

C++ philosophy, 155

cautions, 159

compared to pointed-to values, 172

const keyword, 334–336

declaring, 155–159, 171

deferencing, 171–172

delete operator, 163–164

example, 154

function pointers, 361–362

addresses of functions, obtaining, 362

declaring, 362–363

increment/decrement operators, 210–211

inheritance, 737–739

initializing, 157–159

integers, 160

iterators, 1001

member dereferencing operators, 1242–1246

new operator, 160–162

passing variables, 386–390

pointer arithmetic, 167–172

pointer notation, 173

pointers to objects, 665–670

pointers to pointers, 335

stacks of pointers, 837–843

strings, 173–178

this, 539–546

polar coordinates, 347

converting rectangular coordinates to, 348–351

polymorphic public inheritance, 722–723

base-class functions, 777

Brass class declaration, 723–726

Brass class implementation, 727–731

Brass class objects, 732–733

BrassPlus class declaration, 723–726

BrassPlus class implementation, 727–731

BrassPlus class objects, 732–733

constructors, 742

dynamic binding, 737–740

pointer compatibility, 737–739

reference type compatibility, 737–739

static binding, 737, 740

virtual destructors, 737, 742–743, 776

virtual functions, 739–742, 775–776

behavior, 734–736

friends, 743, 776

memory and execution speed, 742

redefinition, 743–745

virtual function tables, 740

pop() method, 837

popping values off heap, 1314

pop_heap() function, 1305

portability of C++, 15–18

ANSI/ISO standard, 16

limitations, 16

postfixing, 209–210

potential scope, 483

pound sign (#), 234

pow() function, 53

precedence

comma operator, 217

logical operators, 269–270

precedence of operators, 1231

examples, 1234

table of, 1232–1234

precise.cpp, 1082

precision() function, 1082–1083

precision() method, 408

predefined functors, 1030–1032

equivalents for operators, 1032

predicates

adaptable, 1035

binary, 1027–1030

adaptable, 1035

unary, 1027, 1030

prefixing, 209–210

preprocessors, 33–34

prev_permutation() function, 1319

print() functions, 413

printf() function, 29, 44

priority_queue class templates, 1017–1018

priority_queue containers, 1017–1018

private inheritance, 797

base-class components, initializing, 798–799

base-class friends, accessing, 801–804

base-class methods, accessing, 800–801

base-class objects, accessing, 801

compared to containment, 806

Student class example, 798, 804–805

private keyword, 511–513, 798

private member functions, 513

probability() function, 318–320

problem domains, 1207

procedural languages, 11–12

procedural programming, 506–507

procedures. See functions

programming

concurrent programming, 1202–1203

low-level programming, 1203–1204

programming, generic, 992

associative containers, 1018–1026

multimap, 1023–1025

set, 1019–1022

container concepts, 1007–1012

container methods compared to functions, 1039–1041

properties, 1008–1009

sequence requirements, 1011–1012

container types, 1013, 1017–1018

deque, 1013

list, 1014–1017

priority_queue, 1017–1018

queue, 1017

stack, 1018

vector, 1012–1013

iterators, 992, 997–1005

back insert iterators, 1005–1007

bidirectional iterators, 998

concepts, 1000

copy() function, 1001–1002

forward iterators, 998

front insert iterators, 1005–1007

hierarchy, 999–1000

importance of, 992–996

input iterators, 997–998

insert iterators, 1005–1007

istream iterator template, 1003

models, 1001

ostream iterator template, 1002

output iterators, 998

pointers, 1001

random access iterators, 999

reverse iterators, 1003–1005

types, 997

programming exercises

chapter 2, 62–63

chapter 3, 111–113

chapter 4, 192–193

chapter 5, 251–252

chapter 6, 301–303

chapter 7, 374–377

chapter 8, 444–446

chapter 9, 501–503

chapter 10, 559–562

chapter 11, 623–624

chapter 12, 702–705

chapter 13, 780–783

chapter 14, 871–876

chapter 15, 949

chapter 16, 1057–1058

chapter 17, 1148–1151

chapter 18, 1212–1213

programs

comments, 33

/*...*/ notation, 33

// notation, 32

creating main() function, 31

header filenames, 34

iostream file, 33–34

main() function, 29–30

calling, 30

importance of, 32

int main() header, 30–31

myfirst.cpp example, 27–29

comments, 32–33

header filenames, 34

iostream file, 33–34

main() function, 29–32

namespaces, 35–36

output, displaying with cout, 36–39

source code formatting, 39–40

namespaces, 35–36

output, displaying with cout, 36

concatenated output, 46–47

endl notation, 37–38

integer values, 44–45

\n newline character, 38–39

source code formatting, 39

tokens, 39–40

white space, 39

properties

algorithms, 1036–1037

class member functions, 777–778

containers, 1008–1010

reference variables, 390–391

protected classes, 745–746, 775

protected inheritance, 806–807

protected keyword, 745–746, 775, 806

protos.cpp, 310

prototypes (functions), 50–52, 309–311

benefits, 312–313

C++ compared to ANSI C, 312

function prototypes, 1330

syntax, 311–312

pseudorandom numbers, 605

ptrstr.cpp, 174–175

public derivation, 711

public inheritance, 806, 808, 829. See also MI (multiple inheritance)

multiple inheritance, methods, 826

public inheritance (polymorphic), 722–723

base-class functions, 777

Brass class declaration, 723–726

Brass class implementation, 727, 730–731

Brass class objects, 732–733

BrassPlus class declaration, 723–726

BrassPlus class implementation, 727, 730–731

BrassPlus class objects, 732–733

constructors, 742

dynamic binding, 737–740

pointer compatibility, 737–739

reference type compatibility, 737–739

static binding, 737, 740

virtual destructors, 737, 742–743, 776

virtual functions, 739–742, 775–776

behavior, 734–736

friends, 743, 776

memory and execution speed, 742

redefinition, 743–745

virtual function tables, 740

public interfaces, 509

public keyword, 511–513

public member functions, 513

pure virtual functions, 748

push_back() function, 1041

push back() method, 982–984

push_heap() function, 1305

pushing values onto heap, 1314

put() method, 1071–1075

putback() member function, 1109–1114

Q

[top]

qualified, inline, 517

qualified names, 486

qualified names (functions), 514

qualifiers

cv-qualifiers, 472–473

const, 473–474

volatile, 473

keywords, 473

Queue class

class declaration, 691, 694

design, 679

implementation, 680–682

methods, 682–690

public interface, 679–680

queue class templates, 1017

queue containers, 1017

Queue() function, 683

queue simulation, 678

bank.cpp simulation, 694–698

Customer class, 690–691, 694

Queue class

class declaration, 691, 694

design, 679

implementation, 680–682

methods, 682–690

public interface, 679–680

queue.cpp, 692–694

queue.h, 691–692

queuecount() function, 685

queuetp.h, 893–895

quotation marks (), 36

R

[top]

rand() function, 53, 605

random access, files, 1133–1141

temporary files, 1141–1142

random access iterators, 999

Random Walk sample program, 603

random.cpp, 1138–1139

random_shuffle() function, 987–988, 1295, 1302

random_shuffle() STL function, 991

randwalk.cpp, 603

range-based for loop

C++11, 233–234

templates, 1161

range_error exception, 919

ranges, logical AND operator (&&), 265–267

ranges (arrays), 332–334

RatedPlayer class, 711–712

header files, 716

method definitions, 716

RatedPlayer object, 717–718

Rating() method, 719

rbegin() method, 1251, 1275

rdstate() stream state method, 1098–1102

read() member function, 1109–1114, 1130–1133

reading

C-style strings

get(), 127–130

getline(), 126–127

from files, 1116–1118

string class strings, 136–140

text files, 292–298

text with loops, 234

cin.get() function, 235–237, 241–244

cin object, 234–235

end-of-file conditions, 237–241

sentinel characters, 234

real numbers, 50

recommended reading, 1323–1324

rect_to_polar() function, 348–349

rectangular coordinates, 346

converting to polar coordinates, 348–351

recur.cpp, 355, 358

recurs() function, 357–359

recursion, 357

multiple recursive calls, 359–361

single recursive call, 358–359

variadic template functions, 1199–1202

recursive use of templates, 846–847

redefining virtual functions, 743–745

redirecting I/O, 1067–1068

redirection, 238

refcube() function, 391–393

reference, passing by, 343, 386, 389–390, 770

reference arguments, 392–394, 408–409

reference counting, 973

reference operator (&), 383–386

reference parameters, overloading, 415

reference returns, const, 400

reference type, 1273

reference variables, 383

arguments, 408–409

class objects, 401–405

creating, 383–386

function parameters, 386, 389–390

inheritance, 405–408

initialization, 385

properties, 390–391

structures, 394, 397–399

const keyword, 401

return references, 399–400

references

inheritance, 737–739

returning, 399, 770–771

referencing declarations, 463

refinement, 1001

register keyword, 472

reinterpret_cast operators, 946

relational operators, 217–220

C-style strings, comparing, 220–223

equality operator (==), 218–220

functor equivalents, 1031–1032

string class strings, comparing, 223–224

table of, 217

relationships

has-a, 721, 788

is-a, 720–722, 772, 808

remodel() function, 971

remote_access() function, 468

remove_copy() function, 1295, 1300

remove_copy_if() function, 1295, 1300

remove() function, 1295, 1299

remove_if() function, 1295, 1300

remove_if() method, 1280

remove() method, 1280

rend() method, 1251–1252, 1275

replace_copy() function, 1294, 1298

replace_copy_if() function, 1294, 1298

replace() function, 1294, 1298, 1302

replace_if() function, 1294, 1298

replace() method, 1268–1269

replacing strings, 1268–1269

report() function, 859

reserve() method, 966, 1258, 1279

reserved names, 1222–1223

reserved words, 1221

alternative tokens, table of, 1222

keywords, table of, 1221

reserved names, 1222–1223

ResetRanking() method, 718

resize() method, 1047, 1258, 1278

return addresses, 909

return statements, 30

return types, declarations, 1157

return types (functions), 30

return values, 31

return values (functions), 49, 57–59

returning

C-style strings, 341–343

references, 399

structures, 344–345, 348–351

returning objects, 662–664

const objects, 662–665

non-const objects, 663

reverse_copy() function, 1295, 1301

reverse() function, 1295

reverse iterators, 1003–1005

reverse() method, 1252, 1280

reversible containers

associative, multimap, 1023–1025

list, 1014, 1017

member functions, 1014–1016

vector, 1012–1013

review questions

chapter 2, 62

chapter 3, 110–111

chapter 4, 191–192

chapter 5, 250

chapter 6, 298–300

chapter 7, 372–373

chapter 8, 443–444

chapter 9, 498–501

chapter 10, 558–559

chapter 11, 623

chapter 12, 700–702

chapter 13, 779–780

chapter 14, 869–870

chapter 15, 947–949

chapter 16, 1056–1057

chapter 17, 1146–1147

chapter 18, 1209–1212

rewrite rule, 517

rfind() method, 961, 1261

right manipulator, 1091

right shift and assign operator ([]=), 1237

right shift operator ([]), 1236

Ritchie, Dennis, 11

rotate_copy() function, 1295, 1302

rotate() function, 1295, 1301

RTTI (runtime type information), 933–934

incorrect usage, 941–943

operators

dynamic cast, 934–939

typeid, 934, 939, 941, 944

type info class, 939–941, 944

type info structure, 934

rtti1.cpp, 936–938

rtti2.cpp, 939–941

ruler.cpp, 360

runtime, 155

runtime_error exception, 919

runtime type information, 933

rvalue reference, 1162–1164

constructors, C++11, 1256

rvalues, 400

S

[top]

Sales class

sales.cpp, 924

sales.h, 922

use_sales.cpp, 925–927

sales.cpp, 924

sales.h, 922

sayings1.cpp, 656

sayings2.cpp, 665

SCHAR_MAX constant, 72

SCHAR_MIN constant, 72

scientific manipulator, 1091

scope, 454, 483

class, 454, 514

class scope, 549–551

function prototype, 454

global, 454

local, 454–457

namespace, 454

nested classes, 891–892

potential, 483

scope-resolution operator (::), 467, 514, 1332

scoped enumerations, 1158

C++11, 551–552

search() function, 1288, 1292–1293

search_n() function, 1288, 1293

searching strings, 960–961, 1260

find_first_not_of() method, 1262–1263

find_first_of() method, 1262

find_last_not_of() method, 1263

find_last_of() method, 1262

find() method, 1260–1261

rfind() method, 1261

secref.cpp, 385

seekg() method, 1134–1136

seekp() method, 1134–1136

selecting smart pointers, 977–978

sell() function, 516

semantics, move semantics, 1164–1165, 1168–1171

observations, 1171–1172

semicolon (), 29–30

sending messages, OOP, 518

sentinel characters, 234

separate compilation, 447–449, 453

sequence points, 208–209

sequence requirements, container concepts, 1011–1012

sequences

mutating sequence operations

copy_backward() function, 1294–1297

copy() function, 1293–1296

fill() function, 1294, 1299

fill_n() function, 1294, 1299

generate() function, 1294, 1299

generate_n() function, 1294, 1299

iter_swap() function, 1294

partition() function, 1295, 1302–1303

random_shuffle() function, 1295, 1302

remove_copy() function,1295, 1300

remove_copy_if() function, 1295, 1300

remove_if() function, 1295, 1300

remove() function, 1295, 1299

replace_copy() function, 1294, 1298

replace_copy_if() function, 1294, 1298

replace() function, 1294, 1298, 1302

replace_if() function, 1294, 1298

reverse_copy() function, 1295, 1301

reverse() function, 1295

rotate_copy() function, 1295, 1302

rotate() function, 1295, 1301

stable_partition() function, 1295, 1303

swap() function, 1294, 1297

swap_ranges() function, 1294, 1297

transform() function, 1294, 1297

unique_copy() function, 1295, 1301

unique() function, 1295, 1300

nonmodifying sequence operations

adjacent_find() function, 1287, 1290

count() function, 1287, 1291

count_if() function, 1287, 1291

equal() function, 1288, 1291–1292

find_end() function, 1287–1290

find_first_of() function, 1287, 1290

find() function, 1287–1289

find_if() function, 1287–1289

for_each() function, 1287–1289

mismatch() function, 1288, 1291

search() function, 1288, 1292–1293

search_n() function, 1288, 1293

set associative containers, 1019–1022

set flag. See setf() function

set_difference() function, 1021, 1305, 1313

set_intersection() function, 1021, 1305, 1312

set() method, 596, 820

set operations

includes() function, 1305, 1311

set_difference() function, 1305, 1313

set_intersection() function, 1305, 1312

set_symmetric_difference() function, 1305, 1313

set_union() function, 1305, 1312

set_symmetric_difference() function, 1305, 1313

set_terminate() function, 928

set_tot() function, 517–518

set_unexpected() function, 929

set_union() function, 1020–1021, 1305, 1312

setf.cpp, 1085

setf2.cpp, 1088

setf() function, 1083–1087, 1090

arguments, 1087–1089

manipulators, 1090–1091

setf() method, 408

setfill() function, 1091

setops.cpp, 1021–1022

setprecision() function, 1091

sets

methods, 1281–1284

set operations

includes() function, 1305, 1311

set_difference() function, 1305, 1313

set_intersection() function, 1305, 1312

set_symmetric_difference() function, 1305, 1313

set_union() function, 1305, 1312

setstate() stream state method, 1098–1102

setw() function, 1091

shallow copying, 640

shared friends, 888–889

shift operators, 1235–1237

overloading, 581–587

short data type, 68–70

show(), array objects, 357

show_array() function, 327–328

Show() function, 818–820

show() method, 514, 537

show_polar() function, 347, 351

show_time() function, 344–345

showbase manipulator, 1090

showperks() function, 744

showpoint manipulator, 1091

showpos manipulator, 1091

showpt.cpp, 1084

SHRT_MAX constant, 72

SHRT_MIN constant, 72

side effects of expressions, 201, 208–209

signatures (functions), 413

signed char data type, 88–89

singly linked lists, 680

size, string size

finding, 960

automatic sizing feature, 966–967

size() function, 136, 960

size() method, 509, 787, 981, 984, 1251–1252, 1275

size_type constant, 1251

size_type type, 1250, 1273

sizeof operator, 71–73

smart pointers, 1158

selecting, 977–978

sort() function, 987–988, 1041, 1304, 1307

sort_heap() function, 1305

sort() method, 1016–1017, 1280

sort() STL function, 991

sorting

heaps, 1315

nth_element() function, 1304, 1308, 1315

partial_sort_copy() function, 1304, 1307–1308

partial_sort() function, 1304, 1307

sort() function, 1304, 1307

stable_sort() function, 1304, 1307

vectors, 987

source code, 19

definition of, 18

file extensions, 20

special meanings, identifiers, 1223

special member functions, 1178–1179

specializations

explicit, 425, 850–851

example, 426–428

third-generation specialization, 425–426

explicit instantiations, 850

implicit instantiations, 850

partial specializations, 851–852

specifiers

storage class, 472–473

splice() method, 1016, 1280

sqrt.cpp, 51

sqrt() function, 50–52

square() function, 381–382

stable_partition() function, 1295, 1303

stable_sort() function, 1304, 1307

stack, unwinding, 909–910, 913–914

stack class, 831–836

pointers, 837–843

templates, 1018

stack containers, 1018

stack.cpp, 554–555

stack.h, 553–554

stacker.cpp, 556–557

stacks, 553–557

automatic variables, 458–459

stacktem.cpp, 835–836

stacktp.h, 834

standard C++, converting to, 1327

autoptr template, 1333

C++ features, 1331

const instead of #define, 1327–1329

function prototypes, 1330

header files, 1331

inline instead of #define, 1329–1330

namespaces, 1331–1333

STL (Standard Template Library), 1334

string class, 1333

type casts, 1330–1331

Standard Input/Output, ANSI C, 1062

Standard Template Library. See STL

state members, 597–599

statements, 41

assignment statements, 43–44

blocks, 212–214

break, 280–282

cin, 46

loops, 234–235

compared to expressions, 201

continue, 280–282

cout, 36

concatenated output, 46–47

cout.put() function, 83–84

endl manipulator, 37–38

integer values, displaying, 44–45

\n newline character, 38–39

declaration statements, 41–43

defined, 29–30

enum, 278–280

examples, 41, 45

for, declaration-statement expressions, 203

if, 254

bug prevention, 260

example, 255

syntax, 254

if else, 255

example, 256–257

formatting, 257–258

if else if else construction, 258–260

syntax, 255

return statements, 30

switch, 274–278

enumerators as labels, 278–280

example, 275–278

syntax, 275

terminators, 30

void, 53

static assert, 1204

static binding, 164, 172–173, 737, 740

static_cast operator, 945–946

static class members, 628–637

static keyword, 183, 472

functions, 475

static memory storage, 182–183

static storage duration, 453

static type checking, 313

static variables, 453, 459–462, 466

external, 466

external linkage, 463, 466–467

internal linkage, 467–470

no linkage, 470–472

static.cpp, 470–471

stcktp1.h, 839–840

std namespace, 59

stdexcept exception classes, 918–920

Stepanov, Alexander, 978, 1205

stkoptr1.cpp, 841–842

STL (Standard Template Library), 978, 1041, 1044, 1271, 1334

algorithms, 1035

groups, 1035–1036

properties, 1036–1037

associative containers, 1018, 1026

multimap, 1023–1025

set, 1019–1022

binary search operations

binary_search() function, 1304, 1310

equal_range() function, 1304, 1309

lower_bound() function, 1304, 1309

upper_bound() function, 1304, 1309

C++11, 1271

containers, 1271–1273

container concepts, 1007

container methods compared to functions, 1039–1041

properties, 1008–1010

sequence requirements, 1011–1012

container methods, 1275–1277

container types

deque, 1013

list, 1014–1017

priority_queue, 1017–1018

queue, 1017

stack, 1018

vector, 1012–1013

containers, 1161

deque methods, 1278–1280

functions, 1286

adjacent_find(), 1287, 1290

copy(), 1293–1296

copy_backward(), 1294–1297

count(), 1287, 1291

count_if(), 1287, 1291

equal(), 1288, 1291–1292

fill(), 1294, 1299

fill_n(), 1294, 1299

find(), 1287–1289

find_end(), 1287–1290

find_first_of(), 1287, 1290

find_if(), 1287–1289

for_each(), 1287–1289

generate(), 1294, 1299

generate_n(), 1294, 1299

iter_swap(), 1294

mismatch(), 1288, 1291

partition(), 1295, 1302–1303

random_shuffle(), 1295, 1302

remove(), 1295, 1299

remove_copy(), 1295, 1300

remove_copy_if(), 1295, 1300

remove_if(), 1295, 1300

replace(), 1294, 1298, 1302

replace_copy(), 1294, 1298

replace_copy_if(), 1294, 1298

replace_if(), 1294, 1298

reverse(), 1295

reverse_copy(), 1295, 1301

rotate(), 1295, 1301

rotate_copy(), 1295, 1302

search(), 1288, 1292–1293

search_n(), 1288, 1293

stable_partition(), 1295, 1303

swap(), 1294, 1297

swap_ranges(), 1294, 1297

transform(), 1294, 1297

unique(), 1295, 1300

unique_copy(), 1295, 1301

functors, 1026–1027

adaptable, 1032

concepts, 1027–1028, 1030

predefined, 1030–1032

generic programming, 992

heap operations

make_heap() function, 1305, 1314

pop_heap() function, 1305, 1314

push_heap() function, 1305, 1314

sort_heap() function, 1305, 1315

iterators, 997

concepts, 1001

pointers, 1001

list methods, 1278–1280

map methods, 1281–1284

merge operations

inplace_merge() function, 1305, 1311

merge() function, 1305, 1310–1311

methods, 1161

minimum/maximum value operations

lexicographical_compare() function, 1306, 1318

max_element() function, 1305, 1317

max() function, 1305, 1316

min_element() function, 1305, 1317

min() function, 1305, 1316

numeric operations, 1319–1320

accumulate() function, 1320

adjacent_difference() function, 1321–1322

inner_product() function, 1320–1321

partial_sum() function, 1321

permutation operations

next_permutation() function, 1306, 1319

prev_permutation() function, 1319

set methods, 1281–1284

set operations

includes() function, 1305, 1311

set_difference() function, 1305, 1313

set_intersection() function, 1305, 1312

set_symmetric_difference() function, 1305, 1313

set_union() function, 1305, 1312

sorting operations

nth_element() function, 1304, 1308, 1315

partial_sort() function, 1304, 1307

partial_sort_copy() function, 1304, 1307–1308

sort() function, 1304, 1307

stable_sort() function, 1304, 1307

string class, 1038–1039

types, 1273–1274

usealgo.cpp sample program, 1042–1044

using, 1041

vector methods, 1278–1280

Stock class, 511

stock00.h, 510

stock1.cpp, 531

stock1.h, 530

stocks.cpp, class member function, 515

stone.cpp, 610

stone1.cpp, 615

stonetolb() function, 58

stonewt.cpp, 608

stonewt.h, 607

stonewt1.cpp, 614–615

stonewt1.h, 613

storage class qualifiers, 473

storage class specifiers, 472–473

storage duration, 453–454

automatic variables, 455–457

example, 455–457

initializing, 458

stacks, 458–459

scope and linkage, 454

static variables, 459–462

external linkage, 463, 466–467

internal linkage, 467–470

no linkage, 470–472

str1.cpp, 953

str2.cpp, 966–967, 971

strcat() function, 136

strcmp() function, 221–222, 648

strcpy() function, 177–178, 633

strctfun.cpp, 348

strctptr.cpp, 352–353

stream objects, 1067

stream states, 1097–1098

effects, 1100–1102

exceptions, 1099–1100

file I/O, 1118–1119

get() and getline() input effects, 1108

setting, 1098

streambuf class, 1065

streams, 1063–1064, 1067

istream class, 47

ostream class, 47

strfile.cpp, 958–959

strgfun.cpp, 340

strgstl.cpp, 1038–1039

strict weak ordering, 988

strin.cpp, 1144

string class, 131–133, 353–354, 647, 952, 960, 965–966, 1249–1250, 1333

append methods, 1265–1266

assignment, 133–134

assignment methods, 1260, 1266

assignment operator, overloading, 652–658

sayings1.cpp, 656

string1.cpp, 653–656

string1.h, 652–653

automatic sizing, 966–967

bracket notation, 649–651

comparing, 960

comparison members, 648–649

comparison methods, 1263–1265

complex operations, 135–136

concatenation, 133–134

concatenation methods, 1266

constants, 1251

constructors, 952–956, 1253

copy constructors, 1255–1256

default constructors, 1254

that use arrays, 1254

that use n copies of characters, 1257

that use parts of arrays, 1254–1255

that use ranges, 1257

copy methods, 1269

data methods, 1251–1253

default constructor, 647–648

erase methods, 1267–1268

finding size of, 960

Hangman sample program, 962–965

input, 957–960

input/output, 1269–1270

insertion methods, 1267

memory-related methods, 1258

reading line by line, 136–140

replacement methods, 1268–1269

search methods, 1260

find(), 1260–1261

find_first_not_of(), 1262–1263

find_first_of(), 1262

find_last_not_of(), 1263

find_last_of(), 1262

rfind(), 1261

searching, 960–961

static class member functions, 651–652

STL interface, 1038–1039

string access methods, 1259

string comparisons, 223–224

structures, 144–145

template definition, 1249

types, 1250–1251

string() constructors, 952–956, 1253

copy constructors, 1255–1256

default constructors, 1254

that use arrays, 1254

that use n copies of character, 1257

that use parts of arrays, 1254–1255

that use ranges, 1257

string1.cpp, 653–656

string1.h, 653

StringBad class, 628

constructors, 632–633

destructor, 633

strngbad.cpp, 630–631

strngbad.h, 628–629

vegnews.cpp sample program, 633–637

strings

accessing, 1259

accessing with for loops, 206–207

appending, 1265–1266

assigning, 1266

C-style, 120–122

combining with numeric input, 130–131

concatenating, 122

empty lines, 130

failbits, 130

in arrays, 123–124

null characters, 121

passing as arguments, 339–341

pointers, 173–178

returning from functions, 341–343

string input, entering, 124–126

string input, reading with get(), 127–130

string input, reading with getline(), 126–127

comparing, 1263–1265

C-style strings, 220–223

string class strings, 223–224

concatenating, 128, 1266

copying, 1269

erasing, 1267–1268

initializing, 121

input, 1106–1108

input/output, 1269–1270

inserting, 1267

palindromes, 1057

replacing, 1268–1269

searching, 1260

find_first_not_of() method, 1262–1263

find_first_of() method, 1262

find_last_not_of() method, 1263

find_last_of() method, 1262

find() method, 1260–1261

rfind() method, 1261

string access methods, 1259

string class, 131–133, 647, 960, 966, 1249–1250, 1333

append methods, 1265–1266

appending, 133–134

assignment, 133–134

assignment methods, 1260, 1266

assignment operator, overloading, 652–658

automatic sizing, 966–967

bracket notation, 649–651

comparing, 960

comparison members, 648–649

comparison methods, 1263–1265

complex operations, 135–136

concatenation, 133–134

concatenation methods, 1266

constants, 1251

constructors, 952–956, 1253–1257

copy methods, 1269

data methods, 1251–1253

default constructor, 647–648

erase methods, 1267–1268

finding size of, 960

Hangman sample program, 962–965

input, 957–960

input/output, 1269–1270

insertion methods, 1267

memory-related methods, 1258

reading line by line, 136–140

replacement methods, 1268–1269

search methods, 1260–1263

searching, 960–961

static class member functions, 651–652

STL interface, 1038–1039

string access methods, 1259

structures, 144–145

template definition, 1249

types, 1250–1251

string class objects, 353–354

StringBad class, 628

constructors, 632–633

destructor, 633

strngbad.cpp, 630–631

strngbad.h, 628–629

vegnews.cpp sample program, 633–637

swapping, 1269

strings.cpp, 123

strlen() function, 123–124, 136, 177, 306, 632

strngbad.cpp, 630–631

strngbad.h, 629

Stroustrup, Bjarne, 14–15

strout.cpp, 1143

strquote.cpp, 402–403

strtref.cpp, 395

strtype1.cpp, 132

strtype2.cpp, 134

strtype4.cpp, 137

struct keyword, 140

structur.cpp, 142

structure initialization, C++11, 144

structure members, 141

structured programming, 12

structures, 140–142, 343, 346

addresses, passing, 351–353

arrays, 147–148

assignment, 145–146

bit fields, 148

compared to classes, 514

dynamic structures, new operator, 178–180

example, 142–144

nested structures, 682

passing/returning structures, 344–345, 348–351

polar coordinates, 347

rectangular coordinates, 346

reference variables, 394, 397–399

const keyword, 401

return references, 399–400

string class members, 144–145

Student class

contained object interfaces, 792–795

contained objects, initializing, 791

design, 787–788

methods, 793–795

private inheritance, 798, 804–805

base-class components, initializing, 798–799

base-class friends, accessing, 801–804

base-class methods, accessing, 800–801

base-class objects, accessing, 801

sample program, 795–797

studentc.h, 789–790

studentc.cpp, 793

studentc.h, 789–790

studenti.cpp, 802–803

studenti.h, 799

subdivide() function, 360–361

sube() function, 311

subobjects, 797

subroutines. See functions

subscripts, 117

substrings, finding, 1260

find_first_not_of() method, 1262–1263

find_first_of() method, 1262

find_last_not_of() method, 1263

find_last_of() method, 1262

find() method, 1260–1261

rfind() method, 1261

subtraction operator (-), overloading, 574–578

sum_arr() function, 320–322, 325

sum() function, 344–345, 565–567

sum() method, 787, 807, 1046

sumafile.cpp, 294–295

Swap() function, 420–421, 1294, 1297

swap() method, 981, 1269, 1276

swap_ranges() function, 1294, 1297

swapp() function, 389

swapping strings, 1269

swapr() function, 389

swaps.cpp, 387–388

swapv() function, 389

switch.cpp, 276–277

switch statement, 274–278

compared to if else statement, 279–280

enumerators as labels, 278–279

example, 275–278

syntax, 275

symbolic constants, 72

symbolic names, 90–92

T

[top]

TableTennisPlayer class, 708–710

tabtenn0.cpp, 709

tabtenn0.h, 708

usett0.cpp, 710

tabtenn0.cpp, 709

tabtenn0.h, 708

tabtenn1.cpp, 717

tabtenn1.h, 716

tags, 140

Technical Report 1 (TR1), 1206

template aliases, C++11, 866

template classes, 830–837

arrays, non-type arguments, 843–845

auto_ptr, 969, 973–975

complex, 1045

deque, 1013

explicit instantiations, 850

explicit specializations, 850–851

implicit instantiations, 850

list, 1014–1017

member functions, 1014–1016

members, 854–855

partial specializations, 851–852

pointers, stacks of pointers, 837–843

priority_queue, 1017–1018

queue, 1017

stack, 1018

valarray, 1045–1046, 1049–1051

vector, 979–991, 1012–1013, 1045–1046, 1049–1051

adding elements to, 982–983

past-the-end iterators, 981–982

removing ranges of, 982

shuffling elements in, 987

sorting, 987

vect1.cpp example, 980–981

vect2.cpp sample program, 984–986

vect3.cpp sample program, 988–991

versatility, 845–846

default type parameters, 849

multiple type parameters, 847

recursive use, 846–847

template functions, 438

alternative function syntax, 441

decltype, 439

type, 439

template keyword, 831

template parameter packs, 1197–1198

unpacking, 1198–1199

templates. See also STL (Standard Template Library)

angle brackets, 1162

autoptr, 1333

export, 1162

friend classes, 858

bound template friend functions, 861–864

non-template friend functions, 858–861

unbound template friend functions, 864–865

function templates, 419, 422

explicit instantiation, 428–430

explicit specializations, 425–428

implicit instantiation, 428–430

overload resolution, 431–438

overloading, 422–424

inefficiences, function wrapper, 1191–1194

initializer_list, C++11, 1051–1053

istream iterator, 1003

nested classes, 892–896

ostream iterator, 1002–1003

parameters, 855–858

range-based for loop, 1161

STL (Standard Template Library), 1334

string template class, 1249–1250

append methods, 1265–1266

assignment methods, 1260, 1266

comparison methods, 1263–1265

concatenation methods, 1266

constants, 1251

constructors, 1253–1257

copy methods, 1269

data methods, 1251–1253

erase methods, 1267–1268

input/output, 1269–1270

insertion methods, 1267

memory-related methods, 1258

replacement methods, 1268–1269

search methods, 1260–1263

string access methods, 1259

template definition, 1249

types, 1250–1251

valarray, 1162

variadic templates, 866, 1197

recursion, 1199–1202

template and function parameter packs, 1197–1198

unpacking the packs, 1198–1199

tempmemb.cpp, 852

temporary files, random access, 1141–1142

temporary variables, 392–394

tempover.cpp, 434–437

tempparm.cpp, 856–857

terminate() function, 928–930

terminators, 30

testing bit values, 1241–1242

tests, loop tests, 196–197

text, reading with loops, 234

cin.get() function, 235–237, 241–244

cin object, 234–235

end-of-file conditions, 237–241

sentinel characters, 234

text files, 287–288, 1129

reading, 292–298

writing to, 288–292

textin1.cpp, 234

textin2.cpp, 236

textin3.cpp, 239

textin4.cpp, 242

third-generation specialization, 425–426

this pointer, 539

throw keyword, 900

throwing exceptions, 900, 915–916

tilde, 529, 1237

time, 1009

time-delay loops, 229–230

tmp2tmp.cpp, 862–864

toggling bits, 1241

tokens, 39

alternative tokens, table of, 1222

tolower() function, 273, 1041

top-down design, 12

top-down programming, 331

topfive.cpp, 353

topval() method, 543

total ordering, 988

totals, calculating cumulative totals, 1320

toupper() function, 273

trailing zeros/decimal points, printing, 1083–1087, 1090

traits type, 1250

transform() function, 1030–1031, 1041, 1294, 1297

translation units, compiling separately, 447–449, 453

translator (cfront), 21

travel.cpp, 344–345

trivial conversations for exact matches, 432

troubleshooting compilers, 24

truncate.cpp, 1113

try blocks, 901–903

try keyword, 901

turning off bits, 1241

turning on bits, 1241

Tv class, 878–879, 883

tv.cpp, 880–882

tv.h, 879–880

tvfm.h, 885–886

use_tv.cpp, 882

tv.cpp, 880–882

tv.h, 879–880

tvfm.h, 885–886

two-dimensional arrays, 244–249

declaring, 244–246

initializing, 246–249

twoarg.cpp, 316

twod.cpp, 846–847

twofile2.cpp, 469

twoswap.cpp, 427–428

twotemps.cpp, 422

type cast operators, 943–944

type casts, 606–612, 1330–1331

type conversion, 606–612

applying automatically, 616–618

conversion functions, 612–616

friends, 618–621

implicit conversion, 609

type info class, 939–941, 944

type info structure, 934

type parameters, 834

type of template functions, 439

typecast.cpp, 108

typedef, 371

typedef keyword, 230

typeid operators, 934, 939–944

typename keyword, 831

types

char_type, 1250

const_iterator, 1273

const_reference, 1273

difference_type, 1250, 1273

iterators, 997, 1273

key_compare, 1281, 1284

key_type, 1281, 1284

mapped_type, 1281, 1284

reference, 1273

size_type, 1250, 1273

traits, 1250

type casts, 1330–1331

value_compare, 1281, 1284

value_type, 1273

U

[top]

UCHAR_MAX constant, 72

UINT_MAX constant, 72

ULONG_MAX constant, 72

UML (Unified Modeling Language), 08

unary functions, 1027, 1030

unary minus operator, 601

unary operators, 601, 1234

unbound template friend functions, 864–865

uncaught exceptions, 928–931

underscore (_), 1222

unexpected exceptions, 928–931

unexpected() function, 929

unformatted input functions, 1102

Unicode, 88

Unified Modeling Language (UML), 1208

Unified Modeling Language User Guide, 1323

uniform initialization, 1154

initializer_list, 1155

narrowing, 1154

unions, 149

anonymous unions, 150

declaring, 149

unique_copy() function, 1295, 1301

unique() function, 1041, 1295, 1300

unique() method, 1016–1017, 1280

unique_ptr versus auto_ptr, 975–977

universal character names, 87–88

UNIX, CC compiler, 21–22

unnamed namespaces, 491–492

unordered associative containers, C++11, 1283

unqualified names (functions), 486, 514

unsetf() function, 1090

unsigned char data type, 88–89

unsigned integers, 74–76

unsigned long long type, 1153

unwinding the stack, 909–910, 913–914

upcasting, 738, 944

implicit upcasting, 807

update() function, 466, 514

updates, loop updates, 196–198, 205–206

uppercase manipulator, 1091

upper_bound() functions, 1024, 1304, 1309

upper_bound() method, 1021, 1283

use-case analysis, 1207

use() function, 394, 397–399

usealgo.cpp, 1043–1044

usebrass1.cpp, 732–733

usebrass2.cpp, 734

usedma.cpp, 765

usenmsp.cpp, 494–495

user-defined functions

example, 53–54

function form, 54–55

function headers, 55–56

return values, 57–59

using directive, 59–60

usestok0.cpp, 519

usestok1.cpp, 533

usestok2.cp, 547

usetime1.cpp, 571–572

usetime2.cpp, 577

usett0.cpp, 710

usett1.cpp, 717–718

use_new.cpp, 161

use_ptr() method, 1244

use_sales.cpp, 925–927

use_stuc.cpp, 795–797

use_stui.cpp, 804–805

use_tv.cpp, 882

USHRT_MAX constant, 72

using-declaration, 491

using directive, 35–36, 59–60

using keyword, 486–490, 807–808, 1332

V

[top]

valarray class, 786–787, 1045–1046, 1049–1051

templates, 1162

value, passing by, 313–314, 770

value_comp() method, 1282

value_compare type, 1281, 1284

value_type type, 1273

values

assigning to pointers, 171

indirect, 155

valvect.cpp, 1048

variable arrays, 1329

variables, 66

assigning values to, 43

automatic, 182, 453–457

example, 455–457

initializing, 458

stacks, 458–459

automatic variables, 314

declaring, 41–43

dynamic, 454

dynamic memory, 476–479, 482

enum, 150–152

enumerators, 150–151

value ranges, 153

values, setting, 152

floating-point numbers, 92

advantages/disadvantages, 96–97

constants, 96

decimal-point notation, 92

double data type, 94–96

E notation, 92–93

float data type, 94–96

long double data type, 94–96

global, compared to local variables, 467

indeterminate values, 73

initializing, 52, 73

integers, 68

bool, 90

char, 80–89

choosing integer types, 76–77

climits header file, 71–73

constants, 78–80, 90–92

initializing, 73

int, 68–70

long, 68–70

short, 68–70

sizeof operator, 71–73

unsigned, 74–76

width of, 68

keywords, static, 183

local variables, 314–315

compared to global variables, 467

naming conventions, 66–68

pointers, 153

assigning values to, 171

C++ philosophy, 155

cautions, 159

compared to pointed-to values, 172

declaring, 155–159, 171

deferencing, 171–172

delete operator, 163–164

example, 154

initializing, 157–159

integers, 160

new operator, 160–162

pointer arithmetic, 167–172

pointer notation, 173

strings, 173–178

reference variables, 383

arguments, 408–409

class objects, 401–405

creating, 383–386

function parameters, 386, 389–390

inheritance, 405–408

properties, 390–391

structures, 394, 397–401

scope, 454

global, 454

local, 454–457

namespace, 454

static, 453, 459–462

external, 466

external linkage, 463, 466–467

internal linkage, 467–470

no linkage, 470–472

temporary variables, 392–394

type conversions, 102

in arguments, 106

in expressions, 105–106

on assignment, 103–104

type casts, 107–109

variadic templates, 866, 1197

recursion, 1199–1202

template and function parameter packs, 1197–1198

unpacking the packs, 1198–1199

variadic2.cpp, 1201

variations on function pointers, 365–370

vect.cpp, 593

vect.h, 591

vect1.cpp, 980

vect2.cpp, 984–985

vect3.cpp, 988

vector class, 588–590, 600, 979–988, 991, 1045–1046, 1049–1051

adding elements to, 982–983

adding vectors, 590

declaring, 591–592

displacement vectors, 589

implementation comments, 602

member functions, 592, 597

multiple representations, 599

overloaded arithmetic operators, 599–600

overloading overloaded operators, 601

past-the-end iterators, 981–982

Random Walk sample program, 602, 605–606

removing ranges of, 982

shuffling elements in, 987

sorting, 987

state members, 597–599

vect1.cpp example, 980–981

vect2.cpp sample program, 984–986

vect3.cpp sample program, 988–991

vector class templates, 1012–1013

vector containers, 1012–1013

vector objects versus arrays, 188–189

vector template class, 120, 186–187

vectors, methods, 1278–1280

vegnews.cpp, 634

versatility of templates, 845–846

version1() function, 403

version2() function, 404

version3() function, 405

ViewAcct() function, 725–726, 730

virtual base classes, 815–817

combining with nonvirtual base classes, 828

constructors, 817–818

dominance, 828–829

methods, 818–828

virtual destructors, 737, 742–743, 776

virtual function tables (vtbl), 740

virtual functions, 739–742, 775–776

behavior, 734–736

friends, 743, 776

memory and execution speed, 742

pure virtual functions, 748

redefinition, 743–745

virtual function tables, 740

virtual keyword, 742

virtual methods, 1183–1184

void functions, 307

void statement, 53

volatile keyword, 473

vslice.cpp, 1049–1050

vtbl (virtual function table), 740

W

[top]

waiting.cpp, 229

wchar_t data type, 89, 1064

wdith of integers, 68

Web resources, 1325

what() function, 917

while loops, 224–227

compared to for loops, 227–228

example, 225–226

syntax, 224

time-delay loops, 229–230

while.cpp, 225

white space, 39

width() method, 1080–1081

width.cpp, 1080

Windows, compilers, 23–24

Withdraw() method, 731, 745

Worker class, 810–814

Worker0.cpp, 811–812

Worker0.h, 810–811

workermi.cpp, 823–825

workermi.h, 821–822

workmi.cpp, 826–827

worktest.cpp, 813

WorseThan() function, 988

wow() function, 409

wrapped.cpp, 1195

wrappers, 1191

function wrapper

fixing problems, 1194–1196

options for, 1196–1197

template inefficiencies, 1191–1194

write.cpp, 1073–1074

write() member function, 1130–1133

write() method, 1071–1075

writing

to files, 1115–1118

to text files, 288–292

X–Z

[top]

XOR operator, bitwise XOR (^), 1238

zeros, trailing, 1083–1087, 1090