PDF Archive

Easily share your PDF documents with your contacts, on the Web and Social Networks.

Send a file File manager PDF Toolbox Search Help Contact



Thinking in C++.pdf


Preview of PDF document thinking-in-c.pdf

Page 1 2 3 4561104

Text preview


Exercises .......................................193

6: Initialization & cleanup 195
Guaranteed initialization with the
constructor ....................................196
Guaranteed cleanup with the
destructor.......................................197
Elimination of the definition block199
for loops..................................... 201
Storage allocation ........................ 202

Stash with constructors and
destructors.....................................203
Stack with constructors &
destructors.....................................206
Aggregate initialization...............209
Default constructors ....................211
Summary........................................212
Exercises .......................................213

7: Function overloading &
default arguments
215
More name decoration.................216
Overloading on return values ........ 217
Type-safe linkage ........................ 217

Overloading example...................218
unions ............................................221
Default arguments........................225
Placeholder arguments.................. 226

Choosing overloading vs. default
arguments ......................................226
Summary........................................231
Exercises .......................................231

8: Constants

233

Value substitution ........................233

Classes .......................................... 247
const and enum in classes............. 247
Compile-time constants in classes.. 250
const objects & member functions. 253
ROMability................................. 257

volatile .......................................... 257
Summary ....................................... 259
Exercises....................................... 259

9: Inline functions

263

Preprocessor pitfalls .................... 263
Macros and access........................ 266

Inline functions............................ 267
Inlines inside classes..................... 267
Access functions.......................... 268

Stash & Stack with inlines......... 274
Inlines & the compiler................ 274
Limitations.................................. 274
Order of evaluation ...................... 275
Hidden activities in constructors &
destructors................................... 276

Forward referencing.................... 277
Reducing clutter........................... 277
More preprocessor features ....... 278
Token pasting.............................. 279

Improved error checking............ 279
Summary ....................................... 282
Exercises....................................... 282

10: Name control

285

Static elements from C............... 285
static variables inside functions..... 285
Controlling linkage....................... 289
Other storage class specifiers......... 291

Namespaces ................................. 291
Creating a namespace................... 291
Using a namespace ....................... 293

Static members in C++............... 297

const in header files..................... 234
Safety consts............................... 235
Aggregates.................................. 236
Differences with C....................... 236

Defining storage for static data
members..................................... 297
Nested and local classes................ 299
static member functions................ 300

Pointers ..........................................237

Static initialization dependency 303

Pointer to const ........................... 238
const pointer............................... 238
Assignment and type checking...... 239

Function arguments & return
values .............................................240
Passing by const value ................. 240
Returning by const value .............. 241
Passing and returning addresses..... 244

What to do ................................... 304

Alternate linkage specifications 306
Summary ....................................... 307
Exercises....................................... 307