errata.txt
来自「Think in C++文中代码实现」· 文本 代码 · 共 666 行 · 第 1/2 页
TXT
666 行
for loops, 158
storage allocation, 159
stash with constructors and destructors, 161
stack with constructors and destructors, 164
aggregate initialization, 167
default constructors, 170
summary, 172
exercises, 173
4: function overloading & default arguments, 175
more mangling, 177
overloading on return values, 178
type-safe linkage, 179
overloading example, 180
default arguments, 184
a bit vector class, 186
summary, 196
exercises, 198
5: introduction to iostreams, 199
why iostreams?, 200
true wrapping, 202
iostreams to the rescue, 205
sneak preview of operator overloading, 206
inserters and extractors, 207
common usage, 210
line-oriented input, 212
file iostreams, 214
open modes, 217
iostream buffering, 218
using get( ) with a streambuf, 220
seeking in iostreams, 220
creating read/write files, 222
strstreams, 223
user-allocated storage, 224
automatic storage allocation, 228
output stream formatting, 232
internal formatting data, 233
an exhaustive example, 238
formatting manipulators, 242
manipulators with arguments, 243
creating manipulators, 246
effectors, 248
iostream examples, 251
code generation, 251
a simple datalogger, 261
summary, 269
exercises, 270
6: constants, 271
value substitution, 272
const in header files, 273
safety consts, 274
aggregates, 275
differences with C, 276
pointers, 277
pointer to const, 277
const pointer, 278
assignment and type checking, 279
function arguments & return values, 280
passing by const value, 281
returning by const value, 282
passing and returning addresses, 284
classes, 288
const and enum in classes, 288
compile-time constants in classes, 291
const objects & member functions, 294
ROMability, 299
volatile, 300
summary, 302
exercises, 302
7: inline functions, 305
preprocessor pitfalls, 306
macros and access, 310
inline functions, 310
inlines inside classes, 312
access functions, 313
inlines & the compiler, 319
limitations, 320
order of evaluation, 321
hidden activities in constructors & destructors, 322
reducing clutter, 323
preprocessor features, 325
token pasting, 326
improved error checking, 326
summary, 329
exercises, 329
8: name control, 331
static elements from C, 332
static variables inside functions, 332
controlling linkage, 338
other storage class specifiers, 339
namespaces, 340
creating a namespace, 341
using a namespace, 343
static members in C++, 347
defining storage for static data members, 348
nested and local classes, 352
static member functions, 353
static initialization dependency, 356
what to do, 357
alternate linkage specifications, 361
summary, 362
exercises, 362
9: references & the copy-constructor, 365
pointers in C++, 366
references in C++, 366
references in functions, 368
argument-passing guidelines, 371
the copy-constructor, 371
passing & returning by value, 371
copy-construction, 378
default copy-constructor, 385
alternatives to copy-construction, 388
pointers to members, 390
functions, 392
summary, 395
exercises, 396
10: operator overloading, 397
warning & reassurance, 398
syntax, 398
overloadable operators, 400
unary operators, 400
binary operators, 406
arguments & return values, 419
unusual operators, 422
operators you can't overload, 427
nonmember operators, 428
basic guidelines, 430
overloading assignment, 431
behavior of operator=, 433
automatic type conversion, 446
constructor conversion, 446
operator conversion, 448
a perfect example: strings, 451
pitfalls in automatic type conversion, 453
summary, 456
exercises, 456
11: dynamic object creation, 459
object creation, 460
C's approach to the heap, 462
operator new, 464
operator delete, 464
a simple example, 465
memory manager overhead, 466
early examples redesigned, 467
heap-only string class, 467
stash for pointers, 470
the stack, 475
new & delete for arrays, 477
making a pointer more like an array, 479
running out of storage, 479
overloading new & delete, 481
overloading global new & delete, 482
overloading new & delete for a class, 484
overloading new & delete for arrays, 487
constructor calls, 490
object placement, 491
summary, 494
exercises, 494
12: inheritance & composition, 497
composition syntax, 498
inheritance syntax, 500
the constructor initializer list, 502
member object initialization, 503
built-in types in the initializer list, 503
combining composition & inheritance, 505
order of constructor & destructor calls, 507
name hiding, 509
functions that don't automatically inherit, 510
choosing composition vs. inheritance, 513
subtyping, 515
specialization, 518
private inheritance, 520
protected, 521
protected inheritance, 523
multiple inheritance, 523
incremental development, 523
upcasting, 524
why "upcasting"?, 526
composition vs. inheritance (revisited), 527
pointer & reference upcasting, 528
a crisis, 529
summary, 529
exercises, 530
13: polymorphism & virtual functions, 531
evolution of C++ programmers, 532
upcasting, 533
the problem, 535
function call binding, 535
virtual functions, 536
extensibility, 537
how C++ implements late binding, 541
storing type information, 542
picturing virtual functions, 544
under the hood, 546
installing the vpointer, 547
objects are different, 548
why virtual functions?, 549
abstract base classes and pure virtual functions, 551
pure virtual definitions, 556
inheritance and the VTABLE, 557
virtual functions & constructors, 563
order of constructor calls, 564
behavior of virtual functions inside constructors, 565
destructors and virtual destructors, 566
virtuals in destructors, 568
summary, 569
exercises, 570
14: templates & container classes, 573
containers & iterators, 574
the need for containers, 577
overview of templates, 578
the C approach, 578
the Smalltalk approach, 579
the template approach, 581
template syntax, 583
non-inline function definitions, 585
the stack as a template, 586
constants in templates, 589
stash and stack as templates, 591
the ownership problem, 591
stash as a template, 592
stack as a template, 598
string & integer, 603
a string on the stack, 603
integer, 605
vectors, 606
an "infinite" vector, 607
a set, 610
an associative array, 614
templates & inheritance, 618
design & efficiency, 623
preventing template bloat, 623
polymorphism & containers, 625
container types, 629
function templates, 633
a memory allocation system, 633
applying a function to a tstack, 637
member function templates, 640
controlling instantiation, 641
summary, 643
exercises, 644
15: multiple inheritance, 647
perspective, 648
duplicate subobjects, 650
ambiguous upcasting, 651
virtual base classes, 653
the "most derived" class and virtual base initialization, 654
"tying off" virtual bases with a default constructor, 656
overhead, 658
upcasting, 660
persistence, 663
avoiding MI, 672
repairing an interface, 673
summary, 678
exercises, 679
16: exception handling, 681
error handling in C, 682
throwing an exception, 685
catching an exception, 686
the try block, 687
exception handlers, 687
the exception specification, 689
better exception specifications?, 693
catching any exception, 693
rethrowing an exception, 694
uncaught exceptions, 694
cleaning up, 697
constructors, 701
making everything an object, 704
exception matching, 707
standard exceptions, 709
programming with exceptions, 711
when to avoid exceptions, 711
typical uses of exceptions, 713
overhead, 718
summary, 718
exercises, 719
17: run-time type identification, 721
the "shape" example, 722
what is RTTI?, 723
Two syntaxes for RTTI, 724
syntax specifics, 729
typeid( ) with built-in types, 729
producing the proper type name, 729
nonpolymorphic types, 730
casting to intermediate levels, 730
void pointers, 732
using RTTI with templates, 732
references, 733
exceptions, 734
multiple inheritance, 735
sensible uses for RTTI, 736
revisiting the trash recycler, 738
mechanism & overhead of RTTI, 741
creating your own RTTI, 742
new cast syntax, 747
static_cast, 749
const_cast, 751
reinterpret_cast, 752
summary, 755
exercises, 756
A: et cetera, 757
bool, true, and false, 758
new include format, 759
the Standard C++ Libraries, 760
the Standard Template Library (STL), 762
the asm keyword, 766
explicit operators, 767
B: programming guidelines, 769
C: simulating virtual constructors, 781
all-purpose virtual constructors, 782
a remaining conundrum, 787
a simpler alternative, 789
where to find it, 793
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?