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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Turn<strong>in</strong>g variables and<br />

expressions <strong>in</strong>to str<strong>in</strong>gs..... 207<br />

Function addresses 209<br />

Def<strong>in</strong><strong>in</strong>g a function po<strong>in</strong>ter 210<br />

Aside: complicat<strong>ed</strong> declarations<br />

& def<strong>in</strong>itions .................... 210<br />

Us<strong>in</strong>g a function po<strong>in</strong>ter .... 212<br />

Arrays of po<strong>in</strong>ters to functions212<br />

Make: an essential tool<br />

for separate<br />

compilation .......... 214<br />

Make activities ................. 215<br />

Makefiles <strong>in</strong> this book ....... 218<br />

An example makefile ........ 219<br />

Summary............. 221<br />

Exercises ............. 222<br />

4: Data Abstraction 227<br />

A t<strong>in</strong>y C-like library 229<br />

Dynamic storage allocation 233<br />

Bad guesses .................... 237<br />

What's wrong...... 239<br />

The basic object.... 240<br />

What's an object . 248<br />

Abstract data typ<strong>in</strong>g249<br />

Object details ....... 250<br />

Header file etiquette251<br />

Importance of header files. 252<br />

The multiple-declaration<br />

problem .......................... 254<br />

The preprocessor directives<br />

#def<strong>in</strong>e, #ifdef, and #endif 255<br />

A standard for header files 256<br />

Namespaces <strong>in</strong> headers..... 257<br />

Us<strong>in</strong>g headers <strong>in</strong> projects .. 258<br />

Nest<strong>ed</strong> structures.. 258<br />

Global scope resolution ..... 262<br />

Summary............. 263<br />

Exercises ............. 264<br />

5: Hid<strong>in</strong>g the<br />

Implementation 269<br />

Sett<strong>in</strong>g limits........ 270<br />

<strong>C++</strong> access control 271<br />

protect<strong>ed</strong> .........................273<br />

Friends .................273<br />

Nest<strong>ed</strong> friends ..................276<br />

Is it pure ........................279<br />

Object layout ........279<br />

The class ..............280<br />

Modify<strong>in</strong>g Stash to use access<br />

control.............................283<br />

Modify<strong>in</strong>g Stack to use access<br />

control.............................284<br />

Handle classes ......285<br />

Hid<strong>in</strong>g the implementation .286<br />

R<strong>ed</strong>uc<strong>in</strong>g recompilation......286<br />

Summary .............289<br />

Exercises ..............289<br />

6: Initialization &<br />

Cleanup 293<br />

Guarante<strong>ed</strong><br />

<strong>in</strong>itialization with the<br />

constructor ...........295<br />

Guarante<strong>ed</strong> cleanup<br />

with the destructor 297<br />

Elim<strong>in</strong>ation of the<br />

def<strong>in</strong>ition block......299<br />

for loops ..........................301<br />

Storage allocation .............302<br />

Stash with<br />

constructors and<br />

destructors ...........304<br />

Stack with constructors<br />

& destructors ........308<br />

Aggregate <strong>in</strong>itialization311<br />

Default constructors314<br />

Summary .............315<br />

Exercises ..............316<br />

7: Function Overload<strong>in</strong>g<br />

& Default Arguments 319<br />

More name decoration321<br />

Overload<strong>in</strong>g on return values322

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

Saved successfully!

Ooh no, something went wrong!