Table of Contents
Sams Teach Yourself C Plus Plus in One Hour a Day Index
Return to Sams Teach Yourself C Plus Plus in One Hour a Day, Sams Teach Yourself C Plus Plus in One Hour a Day Contents at Glance
Index
A
- C plus plus abstraction, private keyword and, 226–228
- C plus plus final, 307, 332–333
- C plus plus override, 331–332
- C plus plus protected inheritance, 300–301
- C plus plus accumulate() algorithm, 608–609
- C plus plus adaptors, 708, 711–715
- C plus plus addition assignment operator, 356–358, 450–451
- C plus plus addition operator, 353–355
- C plus plus aggregate initialization, 269–272
- C plus plus algorithms, 435–436, 579–580
- C plus plus accumulate(), 608–609
- C plus plus binary predicates and, 561
- C plus plus binary search(), 602–603
constrained, 609–611
count(), 585–587
count if(), 585–587
for each(), 568–569, 592–595
fill(), 589–591
fill n(), 589–591
find(), 583–585, 609
find if(), 570–571, 583–585
generate(), 591–592
generate n(), 591–592
lower bound(), 606–607
mutating, 581–583
non-mutating, 580–581
partition(), 604–606
replace(), 600–601
replace if(), 600–601
reverse(), 456, 496
search(), 587–589
search n(), 587–589
sort(), 496, 575–576, 601–603
stable partition(), 604–606
stable sort(), 604
transform(), 457–458, 573–574, 595–597
unique(), 602–603
upper bound(), 606–607
AND operator, 93–98
append() function, string concatenation, 450–451
applications, multithreaded, 717–718
Area() function, 158
arguments
function, 154, 167–169, 213–215
variable, 423–424
arithmetic operators, 84–85
arrays, 59, 61. See also vectors
accessing data stored in, 63–64
assigning values to elements in, 65
constants and, 61
declaring, 199
displaying elements in, 175
dynamic, 61, 70–71
how data is stored in, 61–63
length of, 66
memory and, 63
modifying data stored in, 64–67
multidimensional, 67
accessing elements in, 68–70
declaring, 67–68
initializing, 68
iterating through, 143–144
need for, 59–60
one-dimensional, 61–62
passing to a function, 166–167
pointers and, 199–202
static, 60–61
ASCII codes, 37, 745–749
assert macro, 409–410
assigning, values to elements in an array, 65
assignment operator, 83, 251
associative containers, 432–434, 440–441
associativity, operator, 106–107
attributes, 415
auto keyword, 44–45, 173–174, 438, 450, 455
B
backslash (\), 72
base class. See also polymorphism
abstract, 324–326
initialization, 285–287
multiple inheritance, 304–306
order of construction, 294
order of destruction, 295–297
private inheritance, 297–300
slicing, 303–304
virtual destructors, 320
begin() function, 493–494, 708
binary files, writing to, 677–678
binary functions, 557–559, 573–575. See also unary functions
binary literals, 47
binary numeral system, 734–735
binary operators, 352–353
addition, 353–355
addition assignment, 356–358
equality, 358–360
greater-than, 361–363
greater-than-or-equal-to, 361–363
inequality, 358–360
less-than, 361–363
less-than-or-equal-to, 361–363
overloadable, 352–353
subtraction, 353–355
subtraction assignment, 356–358
binary predicates, 174, 499, 537–540, 559–561, 575–577
binary search() algorithm, 602–603
bits, 37–38, 735–736. See also memory
bitset class (STL), 633
instantiating, 633–635
member methods, 636–639
operators, 635–636
bitwise operators, 98–102
blocks, 83, 115–116, 124
Boolean variables, 36
braces ({ }), 124
blocks and, 83, 124
nested loops and, 145
break statement, loops and, 137–138
buffer overflow, 75
bugs, 4
building an executable, 3–4, 7–9
bytes, 37, 735–736. See also memory
C C++
advantages of, 2
C and, 1–2
case sensitivity, 17
compilers, 3–4
documentation, 730
ISO standard, 9
online communities, 730
standard strings, 75–77
standardization, 2–3
templates, 428
users, 3
C++20, 1
adaptors, 708, 715
concepts, 700, 707
ranges, 708–709
views, 710, 715
clang++ and, 7
compiler support, 700
constrained algorithms, 609–611
g++, 7, 243, 380, 700, 719
immediate functions, 49–51
modules, 10, 726–727
consuming, 728–729
programming, 727–728
revisions, 10
three-way comparison operator, 90–92, 363–366
C++23 expected features, 729–730
calling functions, 154, 169–171
capacity() function, 477–479
capture lists, 571–573
capturing, variables, 566–567
case conversion, strings, 457–458
case sensitivity, 17
casting, 387
C-style, 388
dynamic, 390–394
need for, 387–388
operators, 388–389
problems with, 396–397
reinterpret cast, 394
syntax, 389
static, 389–390
catch blocks, 684–687
char data type, 37
characters, finding in a string, 451–453
choosing, containers, 438–441
chunking separators, 41
cin, 22–24
for input, 668
for input into a plain old data type, 668–669
for input into std::string, 670–672
writing to a C-style string buffer, 669–670
clang++, 4, 7
classes, 219–220. See also base class; derived class
accessing members
using the dot operator, 222
using the pointer operator, 222–224
aggregate initialization, 269–272
attributes, 415
concepts and, 705–707
constexpr keyword and, 272
declaring, 220–221
friend keyword and, 263–265
inheritance, 277–278
base class initialization, 285–287
derivation and, 278–279
protected keyword, 283
initializing member variables, 229–230
instantiation, 235
naming conventions, 222
objects, 221–222, 549
dot operator and, 222
instantiation, 234
passing objects by value, 242–244
singleton, 251–254
sizeof() operator and, 260–262
STL (Standard Template Library)
bitset, 633–639
exception, 691–694
jthread, 718–721
map, 525–541
multimap, 525–541
multiset, 507–519
priority queue, 623–630
queue, 620–624
set, 507–519
shared ptr, 657
stack, 616–620
streams and, 662–663
string, 443, 445–460
string view, 460–461
stringstream class, 678–680
unique ptr, 655–657
unordered_map, 542–545
unordered_multimap, 542–545
unordered_multiset, 519–522
unordered_set, 519–522
vector, 465–466
vector<bool>, 639–642
string, 441
struct keyword and, 262
template, 415–419
instantiation, 419–421
specialization, 419–421
static members and, 421–423
static variables and, 421–423
unions, 265–268
declaring, 265
instantiating, 266
struct keyword and, 266
without a default constructor, 233–234
clear() function, 482, 495
clone() function, 334–337
close() method, 672–674
collisions, 542
combining multiple adaptors, 713–715
comments, 14, 19
compilers, 3–4, 719
64-bit, 230
casting
C-style, 388
need for, 387–388
clang++, 4
ellipsis, 705
enumerators and, 52
errors, 9
g++, 4
modules, 15
online, 4
parentheses, 108
performance optimization, 172
syntax and, 6
three-way comparison operators and, 92
variables and, 35–36
whitespace and, 82
compile-time checks, 427–428
complexity
constant-time, 433
linear, 433
logarithmic, 433, 541
composition, 303
compound assignment operators, 102–104
compound statements, 83, 115–116
concatenation, strings and, 450–451
concepts, 428, 700–702
classes and, 705–707
custom, 703–705
derived from, 706–707
objects and, 705–707
conditional operator, 124–125
conditional processing
?: operator, 124–125
blocks and, 115–116
if-else construct, 112–114, 119–120
if-else-if construct, 120–121
nested if construct, 117–119
switch-case construct, 121–124
const cast keyword, 394–396
const keyword, 47–48, 372
pointers and, 197–198
references and, 213
constants, 46–47
arrays and, 61
constructors as, 238
defining, 402–404
enumerators, 51–53
keywords and, 55–56
literal, 47, 380–382
constant-time complexity, 433
consteval keyword, 49–51
constexpr keyword, 49, 272
constrained algorithms, 609–611
constructor(s), 228
as constant, 238
converting, 238
copy, 241–242, 251, 654
deep copying, 244–249
shallow copying, 242–244
virtual, 333–334
declaring, 228–229
default, 231, 235
initialization lists and, 236–237
move, 249–250
order of construction, 294
overloaded, 231–232, 233–234
explicit keyword, 257–258
implicit conversions, 256–257
parameters with default values, 234–235
when and how to use, 229–230
contacts list, creating, 499–502
container adapters, 431, 434
containers, 431
adaptive, 615
associative, 432–434, 440–441
choosing, 438–441
complexity, 433
sequential, 431–432, 439
continue statement, loops and, 137–138
controlling, infinite loops, 139–142
conversion operators, 324–326, 346–349
converting constructor, 238
copy assignment operator, 366–370
copy backward() function, 597–599
copy constructor, 241–242, 251, 654
deep copying, 244–249
shallow copying, 242–244
virtual, 333–334
copy() function, 597–599
copy if() function, 597–599
copying, strings, 446–447
count() algorithm, 585–587
count() function, 512, 515, 534–535
count if() algorithm, 585–587
cout, 22–24, 347
aligning text and setting field width, 667–668
changing the display number format, 664–667
statements and, 81–82
streams and, 662
COW (copy on write), 651
creating
contacts list, 499–502
projects
using Microsoft Visual Studio, 5
using Xcode, 5
C-style strings, 72–73
functions and, 75
null terminator, 73
risks of using, 74–75
custom concepts, 703–705
D dangling pointers, 205–206
data types, 39–41. See also variables
auto keyword, 44–45
char, 37
floating-point, 41
signed integer, 38–39
typedef keyword, 46
unsigned integer, 39
debugging, 4
decimal numeral system, 734
converting to binary, 737–738
converting to hexadecimal, 738
declaring
arrays, 199
classes, 220–221
constructors, 228–229
destructors, 238–239
move constructors, 375–376
multidimensional arrays, 67–68
multiple variables of a type, 30
operators, 341
pointers, 180–181, 183
pure virtual functions, 324–325
references, 210
static arrays, 60
templates, 411–412
unions, 265
variables, 28–29, 32
virtual functions, 314–315
decrement operator, 85, 194–196, 344–346
deep copying, 244–249, 366–367
deep-copy smart pointers, 651
default constructors, 231, 235–237
default values, parameter, 158–160
- define, 54–55
constants and, 402–404
writing macro functions, 406–408
defining, lambda expressions, 566
delete operator, 191–194, 202, 316–317
DemoConsoleOutput() function, 21–22
deque class (STL), 479–482
dereference operator, 185–187, 350–351
accessing elements in an array, 201–202
accessing pointed data, 185–187
manipulating data, 187–188
memory and, 186–187
derived class. See also polymorphism
hiding the base class’s methods, 292–294
invoking methods of a base class in a, 290–292
multiple inheritance, 304–306
order of construction, 294
order of destruction, 295–297
overriding the base class’s methods, 287–289
private inheritance and, 300–302
slicing, 303–304
destructive-copy smart pointers, 652–655
destructors, 238, 317–318
deallocation and, 239–241
declaring, 238, 239
exception handling and, 691
implementing, 239
order of destruction, 295–297
private, 254–256
virtual, 318–320
when and how to use, 239
diamond problem, 331
DisplayContents() function, 512, 531
DisplayNums() function, 176
DisplayVector() function, 477
dot operator, 222
do.while loop, 130–132
downcasting, 389
dynamic arrays, 61, 70–71, 465
dynamic casting, 390–394
dynamic memory allocation, 189–190
E for each() algorithm, 568–569, 592–595
encapsulation, 221, 240–241
end() function, 493–494, 708
- endif, 405–406
enumerations, 51–54
equality operator, 87–89, 358–360
erase() function, 453–455, 494–495, 514–519, 535–537
erasing, elements from a list, 494–495
errors, 4, 16. See also debugging; exception(s)
buffer overflow, 75
compiler, 9
exception handling, 206–208
fence-post, 66
narrowing conversion, 43–44
escape character, 72
exception class (STL), 691–694
exception(s), 683–684
catching, 686–687
causes of, 684
handling, 206–208, 678–680, 685–686, 689–691
throwing, 687–689
executable, building, 3–4, 7–9
explicit keyword, 257–258
expressions
constant, 49
lambda, 174, 552
validating, 409–410
F fence-post error, 66
Fibonacci sequence, 145–146, 161–162
files, opening and closing, 672–674
fill() algorithm, 589–591
fill n() algorithm, 589–591
final specifier, 307, 332–333
find() algorithm, 583–585, 609
find() function, 451–453, 512–514, 516–519, 531–534, 542
find if() algorithm, 570–571, 583–585
fixed-width integers, 43
flip() function, 640
fold operations, 608–609
for loop, 132–135
continue statement, 138
infinite, 141
multiple initializations, 135
syntax, 132
forward list class (STL), 502–504
friend keyword, 263–265
fstream class (STL), 672–676
function objects, 549–550. See also lambda expressions
adaptive, 549–550
binary functions, 557–559, 573–575
binary predicates and, 559–561
lambda expressions, 552
structs and, 553
types, 549
unary functions, 550, 553–554
displaying contents of a collection, 551–552
lambda expressions, 568–570
structs and, 550–551
unary predicates and, 554–557
function operator, 373–374
function(s), 20–22, 151. See also algorithms; binary predicates; constructors; destructors; unary predicates
Area(), 158
arguments, 154, 167–169, 213–215
auto keyword, 173–174
begin(), 493–494
calling, 154, 169–171
capacity(), 477–479
clear(), 482, 495
copy(), 597–599
copy backward(), 597–599
copy if(), 597–599
count(), 512, 515, 534–535
C-style strings and, 75
declaration, 21
definition, 154
end(), 493–494
erase(), 453–455, 494–495, 514–519, 535–537
find(), 451–453, 512–514, 516–519, 531–534, 542
flip(), 640
friend keyword and, 263–265
immediate, 49–51
inline, 171–172
insert(), 469–472, 491–495, 529–531
lambda, 174–176
length(), 77
macro, 406–408, 410–411
main(), 15, 21–22, 151, 153, 169, 230
with multiple return statements, 162–163
with no parameters and no return values, 157–158
operators, 341–342
overloaded, 164–166, 167
parameters, 155–156, 158–160
passing a pointer to, 198–199
passing an array of values to, 166–167
pop back(), 475–477
pop front(), 480–482
prototype, 153–154
push back(), 468–469
push front(), 480–482
recursive, 160–162
references and, 212–213
remove(), 598–600
remove if(), 598–600
reserve(), 477–478
return type, 153–154
return value, 21–22
returning a value, 16
reverse(), 496–497
size(), 477–479, 495
sort(), 497–499
strlen(), 75
template, 412–415
vector<bool> class, 640–642
virtual, 313–316, 320–324, 331
Clone(), 334–337
final specifier and, 332–333
override specifier and, 331–332
pure, 324–326
G g++, 4, 7
generate() algorithm, 591–592
generate n() algorithm, 591–592
getline() method, 671–672
global variables, 32–34
goto statement, loops and, 126–128
greater-than operator, 361–363
greater-than-or-equal-to operator, 361–363
grouped if.else construct, 119–120
H hash tables, 541–545
header files, 14, 404–406, 725–726
Hello World, 7–9, 13–14, 662
Hello.cpp, 5–9
hexadecimal notation, 180, 736–737
Hungarian notation, 34
I if…else construct, 112–114
grouped, 119–120
semicolons and, 114
if-else-if statements, 120–121
- ifndef, 405–406
ifstream class (STL), 672–674
immediate functions, 49–51
implementing, destructors, 239
implicit conversions, 256–257, 349
import module, 729
- include, 14–15
increment operator, 85, 194–196, 343–346
inequality operator, 358–360
infinite loops, 138–142
inheritance, 262, 277–278
access specifier, 283
base class
initialization, 285–287
invoking overridden methods of a, 290
derivation and, 278–279
derived class
hiding the base class’s methods, 292–294
invoking methods of a base class in a, 290–292
order of construction, 294
order of destruction, 295–297
overriding the base class’s methods, 287–289
diamond problem, 331
multiple, 279, 304–306, 327–329
private, 297–300
protected, 300–303
protected keyword, 283
public, 307
slicing, 303–304
syntax, 280–282
virtual, 329–331
initialization lists, 236–237, 285–287
initializing
classes, aggregate initialization, 269–272
elements in an array, 61
multidimensional arrays, 68
pointers, 183
STL string class, 445–447
variables, 28, 30, 229–230
inline functions, 171–172
input. See cin
insert() function, 469–472, 491–495, 529–531
instantiation, 233–234
STL bitset class, 633–635
STL list class, 488–489
STL map class, 527–528
STL multimap class, 527–528
STL multiset class, 508–510
STL priority queue class, 625–626
STL queue class, 621–622
STL set class, 508–510
STL stack class, 617–618
STL string class, 445–447
STL vector class, 466–468
STL vector<bool> class, 639–640
template, 416, 700
template classes, 419–421
unions, 266
integers
converting to a string, 678–680
fixed-width, 43
overflow errors and, 39–41
signed, 38–39
unsigned, 39
integrated development environment (IDE), 4
invalid pointers, 203–205
ISO standard for C++, 9
iteration, 130, 143–144
iterators, 134, 434–438, 488, 496, 508–509, 532, 591, 600, 606
accessing character contents of std::string, 448–450
accessing elements in an vector, 474–475
auto keyword and, 438
insert() function and, 470
J-K jthread class, 718–721
key/value pairs, 541–543
keywords, 55–56, 739
auto, 44–45, 173–174, 450, 455
const, 47–48, 372, 404
pointers and, 197–198
references and, 213
const cast, 394–396
consteval, 49–51
constexpr, 49, 272
enum, 51–53
explicit, 257–258
friend, 263–265
private, 224–228, 297
protected, 282–285, 300
public, 223–226
reinterpret cast, 394
requires, 703–705
static, 252
struct, 262, 266
this, 255–259
throw, 687–689
typedef, 46
virtual, 314, 319, 329–331
L lambda
expressions, 552, 565–566
for a binary function, 573–575
for a binary predicate, 575–577
capture lists, 571–573
capturing variables, 566–567
defining, 566
parameters, 567
return types, 567–568
for a unary function, 568–570
for a unary predicate, 570–571
functions, 174–176
lazy initialization, 713
length() function, 77
less-than operator, 361–363
less-than-or-equal-to operator, 361–363
libraries
ranges, 708–709
smart pointer, 658
line breaks, 9
linear complexity, 433
linked list, 487
list class (STL), 487–488
erasing elements from a list, 494–495
inserting elements at the front or back of, 490–491
inserting elements in the middle of a list, 491–494
instantiation, 488–489
reversing and sorting elements in a list, 496–497
sorting and removing elements containing instances of a class, 499–502
sorting elements in, 497–499
lists
erasing elements from, 494–495
forward, 502–504
initialization, 43–44, 469
inserting elements at the front or back of, 490–491
inserting elements in the middle of, 491–494
linked, 487
reversing and sorting elements in, 496–497
sorting, 497–499
sorting and removing elements containing instances of a class, 499–502
literals, 47, 380–382
binary, 47
string, 47
user-defined, 47
local variables, 32
logarithmic complexity, 433, 541
logical operators, 92–94
AND, 94–98
NOT, 95–98
OR, 94–95, 97–98
loops, 66
break statement, 137–138
continue statement, 137–138
do…while, 130–132
for, 132–135
continue statement, 138
multiple initializations, 135
range-based, 135–137
goto statement and, 126–128
infinite, 138–139
nested, 142–143
braces ({ }) and, 145
calculating a Fibonacci sequence, 145–146
iterating through a multidimensional array, 143–144
while, 128–130
lower bound() algorithm, 606–607
l-values, 83
M macOS, 5
macro(s), 402
- define, 54–55
assert, 409–410
defining constants, 402–404
function(s), 406–408, 410–411
parentheses and, 408–409
for protection against multiple inclusion, 404–406
main() function, 15, 21–22, 151, 153, 169, 230
manipulators
setfill(), 667–668
setw(), 667–668
streams and, 663–664
map class (STL), 525–526
erasing elements from a container, 535–537
finding elements in a container, 531–534
inserting elements, 529–531
instantiation, 527–528
supplying a custom sort predicate, 537–541
member selection operator, 350–351
memory, 37
allocation, 189–191
arrays and, 63
checking for successful allocation requests, 206–209
constants and, 46–47
dereference operator and, 186–187
determining the address of a variable, 181–182
dynamic arrays and, 70
hexadecimal notation, 180
increment/decrement operations and, 194–195
invalid pointers, 203–205
leaks, 191, 203, 255, 318
multidimensional arrays and, 68
multiple inheritance and, 329
releasing, 191–194, 239–241
stack, 170–171, 254
storing addresses, 182–185
variables and, 104–106
methods, 221. See also constructors
begin(), 708
close(), 672–674
end(), 708
getline(), 671–672
open(), 672–676
pop(), 619–620, 623–624, 627–630
push(), 619–620, 623–624, 627–630
STL bitset class, 636–639
top(), 628–630
virtual, 325
microprocessor, function calls an, 169–171
Microsoft Visual Studio, creating projects in, 5
modifying, data stored in an array, 64–67
modules, 10, 15, 406, 725
C++20, 726–727
consuming, 728–729
import, 729
programming, 727–728
move assignment operator, 374–380
move constructors, 249–250, 374–380
multidimensional arrays, 67
accessing elements in, 68–70
declaring, 67–68
initializing, 68
iterating through, 143–144
multimap class (STL), 525–526
erasing elements from a container, 535–537
finding elements in a container, 531–535
inserting elements, 529–531
instantiation, 527–528
supplying a custom sort predicate, 537–541
multiple inclusion, macros and, 404–406
multiple inheritance, 279, 304–306, 327–329
multiset class (STL), 507–508
erasing elements in a container, 514–519
finding elements in a container, 512–514
inserting elements, 510–512
instantiation, 508–510
pros and cons of using, 519
multithreading, 717, 718. See also jthread class
mutating algorithms, 581–583
mutexes, 722
N namespaces, 17–18
naming conventions
classes, 222
variables, 30, 34–35
narrowing conversion errors, 43–44
nested if statements, 117–119
nested loops, 142–143
braces ({ }) and, 145
calculating a Fibonacci sequence, 145–146
iterating through a multidimensional array, 143–144
new operator, 1, 190–192, 202, 206–209
non-mutating algorithms, 580–581
NOT operator, 95–98
NULL keyword, 205
null terminator, 73
O object-oriented programming, 228, 277, 285. See also abstraction; encapsulation; inheritance
objects, 3, 221–222
concepts and, 705–707
constexpr keyword and, 272
dot operator and, 222
instantiating, 233
instantiation, 234
ofstream class (STL), 672–675
one-dimensional arrays, 61–62
online
communities, 730
compilers, 4
open() method, 672–676
OR operator, 93–95, 97–98
operators, 342
addition assignment, string concatenation, 450–451
arithmetic, 84–85
assignment, 83, 251
associativity, 106–107
binary, 352–353
addition, 353–355
addition assignment, 356–358
equality, 358–360
greater-than, 361–363
greater-than-or-equal-to, 361–363
inequality, 358–360
less-than, 361–363
less-than-or-equal-to, 361–363
subtraction, 353–355
subtraction assignment, 356–358
bitwise, 98–102
casting
const, 394–396
dynamic, 389–390
problems with, 396–397
reinterpret, 394
static, 389–390
compound assignment, 102–104
conditional, 124–125
copy assignment, 366–370
declaring, 341
decrement, 85
delete, 191–194, 202, 316–317
dereference, 185–187
accessing elements in an array, 201–202
manipulating data, 187–188
memory and, 186–187
dot, 222
equality, 87–89
function, 373–374
functions and, 341–342
increment, 85, 194–196
logical, 92–94
AND, 94–98
NOT, 95–98
OR, 94–98
move assignment, 374–380
move constructor, 374–380
new, 190–194, 202, 206–209
pointer, 222–224
postfix, 85–87
precedence, 106–108, 409
prefix, 41, 85–87
reference, determining the address of a variable, 181–182
relational, 88–90
scope resolution, 229
sizeof(), 42–43, 104–106, 188–189, 260–262, 268
STL bitset class, 635–636
stream extraction, 662
stream insertion, 662
subscript, 370–373
accessing character contents of std::string, 448–450
accessing elements in an array, 472–474
that cannot be overloaded, 382–383
three-way comparison, 90–92, 363–366
unary, 342–343
conversion, 346–349
decrement, 344–346
dereference, 350–351
increment, 343–346
member selection, 350–351
vector<bool> class, 640–642
output. See cout
overflow errors, 39–41
overloadable operators
binary, 352–353
unary, 343
overloaded
constructors, 231–234
explicit keyword, 257–258
implicit conversions, 256–257
functions, 164–167
override specifier, 331–332
overriding the base class’s methods, 331
P parameters
constructor, 234–235
function, 155–156
arrays as, 166–167
with default values, 158–160
lambda expressions, 567
parentheses, 108, 408–409
partition() algorithm, 604–606
partitioning a range, 604–606
passing arguments by reference, 213–215
performance
compilers, 172
complexity and, 433
move constructors, 374–380
move constructors and, 249–250
pointer operator, 222–224
pointers, 179–180
arrays and, 199–202
best practices, 209
const keyword, 197–198
dangling, 205–206
declaring, 180–181, 183
deep copies, 244–249
encapsulation, 240–241
increment operator and, 194–196
initializing, 183
invalid, 203–205
manipulating data, 187–188
memory leaks and, 203
passing to a function, 198–199
problem with using, 645–646
reassigning to another variable, 184–185
shallow copies, 242–244
size of, 188–189
smart, 350–351, 645–646
COW (copy on write) and, 651
deep-copy, 651
destructive-copy, 652–655
implementation, 647–648
libraries, 658
reference-counted, 651–652
reference-linked, 652
types of, 648–649
storing addresses, 182–185
this, 255–259
VFTs (virtual function tables) and, 321–324
polymorphism, 311
abstract base class, 324–326
final specifier, 332–333
need for, 311–313
override specifier, 331–332
pure virtual functions, 324–326
VFTs (virtual function tables), 321–324
virtual destructors, 316–320
virtual functions, 313–316, 320–324
pop back() function, 475–477
pop front() function, 480–482
pop() method, 619–620, 623–624, 627–630
postfix operators, 85–87, 344
precedence, operator, 106–108
prefix operators, 41, 85–87, 343–344
preprocessor directives, 401–402
- define, 54–55
defining constants, 402–404
writing macro functions, 406–408
- endif, 405–406
- ifndef, 405–406
- include, 14–15
headers and, 725–726
priority queue class (STL), 625
instantiating, 625–626
member functions, 627
private
destructor, 254–256
inheritance, 297–300
keyword, 224–228, 297
programming languages
object-oriented, 228
runtime, 2
programs
comments, 19
Hello World, 13–14
main(), 15
namespaces, 17–18
preprocessor directives, 14–15
streams, 15–16
projects, creating
using Microsoft Visual Studio, 5
using Xcode, 5
pronouncing special characters, 6
protected
inheritance, 300–303
keyword, 282–285, 300
prototypes, function, 153–154
public
inheritance, 278–279, 307. See also inheritance; private inheritance
keyword, 223–226
pure virtual functions, 324–326
push back() function, 468–469
push front() function, 480–482
push() method, 619–620, 623–624, 627–630
Q queue class (STL), 620–621
instantiating, 621–622
member functions, 622–623
pop() method, 623–624
push() method, 623–624
queues, 616
quotation marks, chunking separators, 41
R RAM (random access memory), 27, 30. See also memory
range, 708
partitioning, 604–606
performing transformations on a, 595–597
processing elements in a, 592–595
range-based for loop, 135–137
ranges library, 708–709
adaptors, 711–715
views, 709–711
reading a text file, 675–676
recursive functions, 160–162
reference operator, determining the address of a variable, 181–182
reference-counted smart pointers, 651–652
reference-linked smart pointers, 652
references, 210–212
const keyword, 213
declaring, 210
functions, 212–213
refinement, 435
reinterpret cast, 394
relational operators, 88–90
releasing, allocated memory, 191–194
remove() function, 598–600
remove if() function, 598–600
replace() algorithm, 600–601
replace if() algorithm, 600–601
requires keyword, 703–705
reserve() function, 477–478
reserved words, 55–56
return types, lambda expressions, 567–568
returning a value, 16
reverse() algorithm, 456, 496–497
RTTI (runtime type identification), 324, 391
runtime, 2, 222
r-values, 83
S scope, variables, 30–32
scope resolution operator, 229
scoped enumerations, 53–54
search() algorithm, 587–589
search n() algorithm, 587–589
semaphores, 722
semicolons, conditional processing and, 114
sequential containers, 431–432, 439
set class (STL), 507–508
erasing elements in a container, 514–519
finding elements in a container, 512–514
inserting elements, 510–512
instantiation, 508–510
pros and cons of using, 519
setfill() manipulator, 667–668
setw() manipulator, 667–668
shallow copying, 242–244
shared ptr class (STL), 657
shift operators, 100–102
signed integers, 37–39
singleton class, 251–254
size() function, 477–479, 495
sizeof() operator, 42–43, 104–106, 188–189, 268
classes and, 260–262
variable templates and, 425
slicing, 303–304, 649
smart pointers, 350–351, 645––646
COW (copy on write) and, 651
deep-copy, 651
destructive-copy, 652–655
implementation, 647–648
libraries, 658
reference-counted, 651–652
reference-linked, 652
types of, 648–649
sort() algorithm, 496, 575–576, 601–603
sort() function, 497–499
sorting, lists, 497–499
spaghetti code, 128
special characters, pronouncing, 6
splitting statements, 82
stable partition() algorithm, 604–606
stable sort() algorithm, 604
stack class (STL), 616–617
instantiating, 617–618
member functions, 618–620
pop() method, 619–620
push() method, 619–620
stacks, 170–171, 254, 615–616
statements, 81
compound, 83
cout and, 81–82
iterative, 130
splitting, 82
static
arrays, 60–61
casting, 389–390
keyword, 252
variables, 421–423
static_assert, 427–428
std namespace, 17–18
std: :string, 75–77
STL (Standard Template Library), 373, 428, 431. See also cin; cout
algorithms, 435–436, 579–580
accumulate(), 608–609
binary predicates and, 561
binary search(), 602–603
count(), 585–587
count if(), 585–587
find(), 583, 584–585, 609
find if(), 570–571, 583–585
generate(), 591–592
generate n(), 591–592
lower bound(), 606–607
mutating, 581–583
non-mutating, 580–581
partition(), 604–606
replace(), 600–601
replace if(), 600–601
reverse(), 456
sort(), 575–576, 601–603
stable partition(), 604–606
stable sort(), 604
transform(), 457–458, 573–574, 595–597
unique(), 602–603
upper bound(), 606–607
bitset class, 633
instantiating, 633–635
member methods, 636–639
operators, 635–636
concepts, 701–702
container adapters, 434
containers, 431
associative, 432–434, 440–441
complexity, 433
sequential, 431–432, 439
deque class, 479–482
exception class, 691–694
forward list class, 502–504
fstream class, 672
iterators, 434–438
jthread class, 718–721
list class, 487–488
erasing elements from a list, 494–495
inserting elements at the front or back of, 490–491
inserting elements in the middle of a list, 491–494
instantiation, 488–489
reversing and sorting elements in a list, 496–497
sorting and removing elements containing instances of a class, 499–502
sorting elements in, 497–499
map class, 525–526
erasing elements from a container, 535–537
finding elements in a container, 531–534
inserting elements, 529–531
instantiation, 527–528
multimap class, 525–526
erasing elements from a container, 535–537
finding elements in a container, 531–535
inserting elements, 529–531
instantiation, 527–528
supplying a custom sort predicate, 537–541
multiset class, 507–508
erasing elements in a container, 514–519
finding elements in a container, 512–514
inserting elements, 510–512
instantiation, 508–510
pros and cons of using, 519
priority queue class, 625
instantiating, 625–626
member functions, 627
pop() method, 627–630
push() method, 627–630
top() method, 628–630
queue class, 620–621
instantiating, 621–622
member functions, 622–623
pop() method, 623–624
push() method, 623–624
set class, 507–508
erasing elements in a container, 514–519
finding elements in a container, 512–514
inserting elements, 510–512
instantiation, 508–510
pros and cons of using, 519
shared ptr class, 657
stack class, 615–616
instantiating, 617–618
member functions, 618–-620
pop() method, 619–620
push() method, 619–620
streams and, 662–663
string class, 443
accessing character contents of, 448–450
copy techniques, 446–447
erase() function, 453–455
find() function, 451–453
instantiating, 445–447
need for, 443–444
operator ““s, 459–460
template-based implementation, 458
working with, 445
string classes, 441
string view class, 460–461
stringstream class, 678–680
unique ptr class, 655–657
unordered_map class, 542–545
unordered_multimap class, 542–545
unordered_multiset class, 519–522
unordered_set class, 519–522
vector class
accessing elements using array semantics, 472–474
accessing elements using pointer semantics, 474–475
characteristics, 465–466
inserting elements at a given position, 469–472
inserting elements at the end of a vector, 468–469
instantiating, 466–468
removing elements from a vector, 475–477
typical operations, 466
vector<bool> class, 639
flip() function, 640
instantiating, 639–640
member functions and operators, 640–642
wstring class, 458
stray pointers, 205–206
stream extraction operator, 662
stream insertion operator, 662
streams, 15–16, 661
cin
for input, 668
for input into a plain old data type, 668–669
for input into std::string, 670–672
writing to a C-style string buffer, 669–670
classes, 662–663
closing, 672–674
cout, 662
aligning text and setting field width, 667–668
changing the display number format, 664–667
fstream class, 672, 675–676
manipulators, 663–664
ofstream class, 674–675
opening, 672–674
writing to a binary file, 677–678
string class (STL), 441, 443
accessing character contents of, 448–450
copy techniques, 446–447
erase() function, 453–455
find() function, 451–453
instantiating, 445–447
need for, 443–444
operator ”“s, 459–460
template-based implementation, 458
working with, 445
strings, 75–77
case conversion, 457–458
classes, 441, 443–444. See also STL (Standard Template Library), string class
concatenation, 450–451
converting to an integer, 678–680
copying, 446–447
C-style, 72–73
functions and, 75
null terminator, 73
risks of using, 74–75
finding a character or substring in a, 451–453
literals, 16, 47
reversal, 455–456
truncating, 453–455
stringstream class (STL), 678–680
strlen() function, 75
Stroustrop, Bjarne, 1
struct keyword, 262, 266, 540
structs, 552
function objects and, 553
unary functions and, 550–551
subscript operator, 370–373
accessing character contents of std::string, 448–450
accessing elements in an array, 472–474
substring, finding in a string, 451–453
subtraction assignment operator, 356–358
subtraction operator, 353–355
switch-case construct, 121–124
synchronizing threads, 722
syntax
casting operators, 389
compilers and, 6
do.while loop, 130
dynamic cast operator, 390
goto statement, 126
inheritance, 280–282
lambda expressions, 566
lambda functions, 176
for loop, 132
move constructors, 249–250
switch-case construct, 121
three-way comparison operator, 363
while loop, 128
T template(s), 411, 700. See also STL (Standard Template Library)
classes, 415–419
instantiation, 419–421
specialization, 419–421
static members and, 421–423
static variables and, 421–423
declaring, 411–412
with default parameters, 417
functions, 412–415
instantiation, 416, 700
with multiple parameters, 416–417
in practical C++ programming, 428
static_assert, 427–428
type safety and, 415
variable, 423–426
text editors, 3
text file
reading, 675–676
writing to, 662, 674–675
this pointer, 255–259
threads, 717
data sharing and, 721–722
synchronization, 718
synchronizing, 722
three-way comparison operator, 90–92, 363–366
throw keyword, 687–689
tiered architecture, 2
top() method, 628–630
transform() algorithm, 457–458, 573–574, 595–597
try blocks, 684–686
tuples, 425–426
typedef keyword, 46
U unary functions, 550, 553–554
displaying contents of a collection, 551–552
lambda expressions, 568–570
structs and, 550–551
unary predicates and, 554–557
unary operators, 342–343
conversion, 346–349
decrement, 344–346
dereference, 350–351
increment, 343–346
member selection, 350–351
unary predicates, 554–557, 570–571
unions, 265–268
declaring, 265
instantiating, 266
struct keyword and, 266
unique() algorithm, 602–603
unique ptr class (STL), 655–657
unordered_map class (STL), 542–545
unordered_multimap class (STL), 542–545
unsigned integers, 37–41
upcasting, 389
upper bound() algorithm, 606–607
user-defined literals, 47, 380–382
using namespace declaration, 17–18
V validating, expressions, 409–410
variable(s), 28
Boolean, 36
capturing, 566–567
char, 37
class member, initializing, 229–230
const keyword, 47–48
constexpr keyword, 49
declaring, 28–30, 32
defining, 28
determining the address of, 181–182
determining the size of, 42–43
enumerations, 51–54
floating-point, 41
global, 32–34
initializing, 28, 30
keywords and, 55–56
local, 32
memory and, 104–106
naming conventions, 30, 34–35
narrowing conversion errors, 43–44
overflow errors and, 39–41
pointer, 179–180
arrays and, 199–202
best practices, 209
const keyword and, 197–198
dangling, 205–206
declaring, 180–181, 183
increment operator and, 194–196
initializing, 183
invalid, 203–205
manipulating data, 187–188
memory leaks and, 203
passing to a function, 198–199
reassigning to another variable, 184–185
size of, 188–189
storing addresses, 182–185
references and, 210
scope, 30–32
signed types, 38–39
static, 421–423
templates, 423–426
types, 35–36
unsigned types, 39
vector class (STL)
accessing elements using array semantics, 472–474
accessing elements using pointer semantics, 474–475
characteristics, 465–466
inserting elements at a given position, 469–472
inserting elements at the end of a vector, 468–469
instantiating, 466–468
removing elements from a vector, 475–477
typical operations, 466
vector<bool> class (STL), 639
flip() function, 640
instantiating, 639–640
member functions and operators, 640–642
vectors, 71. See also STL (Standard Template Library), vector class
accessing elements
using array semantics, 472–474
using pointer semantics, 474–475
capacity() function and, 477–479
deque and, 480
inserting elements at a given position, 469–472
inserting elements at the end of, 468–469
removing elements from, 475–477
reserve() function and, 477–478
size() function and, 477, 478–479
VFTs (virtual function tables), 321–324
views, 708–711
virtual copy constructors, 333–334
virtual destructors, 316–320
virtual functions, 313–316, 331. See also VFTs (virtual function tables)
Clone(), 334–337
final specifier and, 332–333
override specifier and, 331–332
pure, 324–326
virtual inheritance, 329–331
Visual Studio Code, 7
W while loop, 128–130
whitespace, 82
wild pointers, 205–206
writing
to a binary file, 677–678
code, best practices, 741–743
to a C-style string buffer, 669–670
to a text file, 674–675
wstring class (STL), 458
X Xcode
compiling C++20 code, 8
creating a new C++ project, 5
XOR operator, 94
Y-Z zero-based index, 63–64, 71
Fair Use Sources
Cloud Monk is Retired ( for now). Buddha with you. © 2025 and Beginningless Time - Present Moment - Three Times: The Buddhas or Fair Use. Disclaimers
SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.