Index

Symbols

<=, 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

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

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

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

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

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

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

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

Загрузка...