04.01.2015 Views

Thinking in C++ 2nd ed Volume 1 Revision 6

Thinking in C++ 2nd ed Volume 1 Revision 6

Thinking in C++ 2nd ed Volume 1 Revision 6

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The copy-constructor465<br />

Pass<strong>in</strong>g & return<strong>in</strong>g by value465<br />

Copy-construction ............ 472<br />

Default copy-constructor ... 478<br />

Alternatives to copyconstruction<br />

.................... 481<br />

Po<strong>in</strong>ters to members483<br />

Functions ........................ 485<br />

Summary............. 488<br />

Exercises ............. 489<br />

12: Operator<br />

Overload<strong>in</strong>g 493<br />

Warn<strong>in</strong>g & reassurance494<br />

Syntax................. 495<br />

Overloadable operators496<br />

Unary operators ............... 497<br />

B<strong>in</strong>ary operators .............. 501<br />

Arguments & return values 512<br />

Unusual operators ............ 515<br />

Operators you can’t overload524<br />

Nonmember operators525<br />

Basic guidel<strong>in</strong>es ............... 527<br />

Overload<strong>in</strong>g<br />

assignment .......... 528<br />

Behavior of operator=....... 529<br />

Automatic type<br />

conversion ........... 541<br />

Constructor conversion ..... 541<br />

Operator conversion ......... 543<br />

Type conversion example .. 545<br />

Pitfalls <strong>in</strong> automatic type<br />

conversion....................... 547<br />

Summary............. 549<br />

Exercises ............. 550<br />

13: Dynamic Object<br />

Creation 555<br />

Object creation ..... 557<br />

C’s approach to the heap... 558<br />

operator new ................... 560<br />

operator delete ................ 560<br />

A simple example............. 561<br />

Memory manager overhead 562<br />

Early examples<br />

r<strong>ed</strong>esign<strong>ed</strong>............563<br />

delete void* is probably a bug563<br />

Cleanup responsibility with<br />

po<strong>in</strong>ters...........................565<br />

Stash for po<strong>in</strong>ters .............565<br />

new & delete for arrays571<br />

Mak<strong>in</strong>g a po<strong>in</strong>ter more like an<br />

array ...............................572<br />

Runn<strong>in</strong>g out of storage573<br />

Overload<strong>in</strong>g new &<br />

delete ..................574<br />

Overload<strong>in</strong>g global new &<br />

delete..............................575<br />

Overload<strong>in</strong>g new & delete for a<br />

class ...............................578<br />

Overload<strong>in</strong>g new & delete for<br />

arrays .............................581<br />

Constructor calls...............584<br />

placement new & delete.....585<br />

Summary .............588<br />

Exercises ..............588<br />

14: Inheritance &<br />

Composition 591<br />

Composition syntax592<br />

Inheritance syntax .594<br />

The constructor<br />

<strong>in</strong>itializer list .........596<br />

Member object <strong>in</strong>itialization 597<br />

Built-<strong>in</strong> types <strong>in</strong> the <strong>in</strong>itializer<br />

list ..................................597<br />

Comb<strong>in</strong><strong>in</strong>g composition<br />

& <strong>in</strong>heritance ........599<br />

Order of constructor &<br />

destructor calls.................600<br />

Name hid<strong>in</strong>g .........603<br />

Functions that don’t<br />

automatically <strong>in</strong>herit608<br />

Inheritance and static member<br />

functions..........................612<br />

Choos<strong>in</strong>g composition<br />

vs. <strong>in</strong>heritance ......612<br />

Subtyp<strong>in</strong>g ........................614<br />

private <strong>in</strong>heritance ............616

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!