![]() |
James Thornton |
| Internet Business Consultant | Call Toll Free: 1 (800) 409-2501 |
| About James | My MySpace | Internet Marketing | Enron Loophole | Lock Bumping | Contact Me |
|---|
Front Pages
Preface
What’s new in the second edition
1: Introduction to Objects
Prerequisites
Learning C++
Goals
Chapters
Exercises
Source code
Language standards
The book’s CD ROM
CD ROMs, seminars, and consulting
Errors
About the cover
Book design and production
Acknowledgements
The progress of abstraction
2: Making & Using Objects
An object has an interface
The hidden implementation
Reusing the implementation
Inheritance: reusing the interface
Interchangeable objects with polymorphism
Creating and destroying objects
Exception handling: dealing with errors
Analysis and design
Phase 0: Make a plan
Extreme programming
Phase 1: What are we making?
Phase 2: How will we build it?
Phase 3: Build the core
Phase 4: Iterate the use cases
Phase 5: Evolution
Plans pay off
Why C++ succeeds
A better C
Strategies for transition
You’re already on the learning curve
Efficiency
Systems are easier to express and understand
Maximal leverage with libraries
Source-code reuse with templates
Error handling
Programming in the large
Guidelines
Summary
1. Training
Management obstacles
2. Low-risk project
3. Model from success
4. Use existing class libraries
5. Don’t rewrite existing code in C++
The process of language translation
3: The C in C++
Tools for separate compilation
Declarations vs. definitions
Your first C++ program
Function declaration syntax
Linking
A gotcha
Function definitions
Variable declaration syntax
Including headers
Standard C++ include format
Using libraries
Using the iostreams class
More about iostreams
Namespaces
Fundamentals of program structure
"Hello, world!"
Running the compiler
Introducing strings
Reading and writing files
Introducing vector
Summary
Exercises
Creating functions
4: Data Abstraction
Controlling execution
True and false
Introduction to operators
if-else
while
do-while
for
The break and continue keywords
switch
Using and misusing goto
Recursion
Introduction to data types
Basic built-in types
Scoping
bool, true, & false
Specifiers
Introduction to pointers
Modifying the outside object
Introduction to C++ references
Pointers and references as modifiers
Specifying storage allocation
Operators and their use
Assignment
Composite type creation
Mathematical operators
Relational operators
Logical operators
Bitwise operators
Shift operators
Unary operators
The ternary operator
The comma operator
Common pitfalls when using operators
Casting operators
C++ explicit casts
sizeof – an operator by itself
The asm keyword
Explicit operators
Aliasing names with typedef
Debugging hints
Combining variables with struct
Clarifying programs with enum
Saving memory with union
Arrays
Function addresses
Defining a function pointer
Make: managing separate compilation
Complicated declarations & definitions
Using a function pointer
Arrays of pointers to functions
Summary
Exercises
A tiny C-like library
5: Hiding the Implementation
What's wrong?
The basic object
What's an object?
Abstract data typing
Object details
Header file etiquette
Importance of header files
Nested structures
The multiple-declaration problem
The preprocessor directives #define, #ifdef, and #endif
A standard for header files
Namespaces in headers
Using headers in projects
Summary
Exercises
6: Initialization & Cleanup
Guaranteed initialization with the constructor
7: Function Overloading & Default Arguments
Guaranteed cleanup with the destructor
Elimination of the definition block
Stash with constructors and destructors
Stack with constructors & destructors
Aggregate initialization
Default constructors
Summary
Exercises
More name decoration
8: Constants
Overloading example
unions
Default arguments
Choosing overloading vs. default arguments
Summary
Exercises
Value substitution
9: Inline Functions
Pointers
Function arguments & return values
Classes
volatile
Summary
Exercises
Preprocessor pitfalls
10: Name Control
Inline functions
Stash & Stack with inlines
Inlines & the compiler
Reducing clutter
More preprocessor features
Improved error checking
Summary
Exercises
Static elements from C
11: References & the Copy-Constructor
Namespaces
Static members in C++
Static initialization dependency
Alternate linkage specifications
Summary
Exercises
Pointers in C++
12: Operator Overloading
References in C++
The copy-constructor
Passing & returning by value
Pointers to members
Passing & returning large objects
Copy-construction
Function-call stack frame
Re-entrancy
Bitcopy versus initialization
Default copy-constructor
Alternatives to copy-construction
Summary
Exercises
Warning & reassurance
13: Dynamic Object Creation
Syntax
Overloadable operators
Unary operators
Non-member operators
Binary operators
Arguments & return values
Unusual operators
Operators you can’t overload
Overloading assignment
Automatic type conversion
Constructor conversion
Summary
Operator conversion
Type conversion example
Pitfalls in automatic type conversion
Exercises
Object creation
14: Inheritance & Composition
Early examples redesigned
new & delete for arrays
Running out of storage
Overloading new & delete
Overloading global new & delete
Summary
Overloading new & delete for a class
Overloading new & delete for arrays
Constructor calls
placement new & delete
Exercises
Composition syntax
15: Polymorphism & Virtual Functions
Inheritance syntax
The constructor initializer list
Combining composition & inheritance
Order of constructor & destructor calls
Name hiding
Functions that don’t automatically inherit
Choosing composition vs. inheritance
protected
Operator overloading & inheritance
Multiple inheritance
Incremental development
Upcasting
Why “upcasting?”
Summary
Upcasting and the copy-constructor
Composition vs. inheritance (revisited)
Pointer & reference upcasting
A crisis
Exercises
Evolution of C++ programmers
16: Introduction to Templates
Upcasting
The problem
virtual functions
How C++ implements late binding
Storing type information
Why virtual functions?
Picturing virtual functions
Under the hood
Installing the vpointer
Objects are different
Abstract base classes and pure virtual functions
Inheritance and the VTABLE
Overloading & overriding
virtual functions & constructors
Destructors and virtual destructors
Operator overloading
Downcasting
Summary
Exercises
Containers
A: Coding Style
Overview of templates
Template syntax
Stack and Stash as templates
Turning ownership on and off
Holding objects by value
Introducing iterators
Why iterators?
Summary
Exercises
B: Programming Guidelines
C: Recommended Reading
Index
James Thornton,
jamesthornton.com>
Services: Search Engine Optimization Consulting
Electric Speed: Search Engine Optimization Services