H

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

XOR operator, bitwise XOR (^), 1238

zeros, trailing, 1083–1087, 1090

Загрузка...