1. Memory Organization
1.1 Physical Memory
1.2 Logical Memory
1.3 Computational Models
1.3.1 Static Allocation
1.3.2 Temporary Dynamic Allocation
1.3.3 Persistent Dynamic Allocation
1.4 Software Engineering
1.4.1 The Costs of Computing
1.4.2 The Cost of Bugs
1.4.3 Design Prioritization
1.5 Summary
1.6 Key Terms
2. Fundamentals
2.1 Code to Execution
2.2 Identifiers
2.2.1 Declarations
2.2.2 Definitions
2.2.3 Input/Output and main()
2.2.4 Addressing
2.2.5 Constants
2.3 Typing
2.3.1 The Character Type
2.3.2 Wide Characters
2.3.3 Character Strings
2.3.4 Integers
2.3.5 Boolean
2.3.6 Floating Point
2.3.7 Operators
2.3.8 Casting
2.4 Control Structures
2.4.1 Selection
2.4.2 Repetition
2.5 Functions
2.5.1 Inlining
2.5.2 Scoping
2.6 Static Variables
2.7 Summary
2.8 Key Terms
2.9 Exercises
2.9.1 Conceptual Review
2.9.2 Trace/Analysis Exercises
2.9.3 Programming Exercises
3. Pointers
3.1 Address Holders
3.1.1 Memory Allocation and Initialization
3.1.2 Persistence
3.1.3 A Sample Compiler Trace
3.1.4 Pointer Declarations
3.2 Pointer Type
3.2.1 Typed Pointers
3.2.2 Void Pointers
3.2.3 Pointer Declarations
3.2.4 Pointer Initialization
3.2.5 The Null Pointer
3.2.6 Dereferencing Pointers
3.2.7 Unintended Aliasing
3.2.8 Rogue (Uninitialized) Pointers
3.2.9 main() Revisited
3.3 Dynamic Memory Allocation
3.3.1 The new Operator
3.3.2 Run-time Allocation Errors
3.3.3 The Need to Initialize Dynamic Memory
3.3.4 Memory Leakage
3.3.5 Inaccessible Dynamic Memory (More Leakage)
3.3.6 Fooling the Default Allocator
3.4 Constant Pointers and Pointers to Constants
3.5 Aliases and References
3.6 The Overhead of Indirection
3.7 Pointers Hidden by the Compiler
3.8 Summary
3.9 Key Terms
3.10 Exercises
3.10.1 Conceptual Review
3.10.2 Trace/Analysis Exercises
3.10.3 Programming Exercises
4. Classes
4.1 Object-Oriented Programming
4.2 Implementation details
4.2.1 Information-Hiding
4.2.2 Association between Object and Member Data
4.2.3 The this Pointer
4.2.4 Mutators
4.2.5 Constructors
4.2.6 Conversion Constructors
4.2.7 Safety
4.2.8 Destructors
4.3 Dynamic Allocation within Objects
4.3.1 Constructors and Dynamic Allocation
4.3.2 Copy Constructors
4.3.3 Overloaded Assignment Operators
4.3.4 Destructors and Dynamic Allocation
4.3.5 Clean-up Functions
4.3.6 Safety
4.4 Arrays
4.5 const Objects
4.6 Static Constructors and Destructors
4.7 Summary
4.8 Key Terms
4.9 Exercises
4.9.1 Conceptual Review
4.9.2 Trace/Analysis Exercises
4.9.3 Programming Exercises
5. Other User-Defined Types
5.1.1 Arrays as Pointers
5.1.2 Pointer Arithmetic
5.1.3 Pseudodynamic Arrays
5.1.4 Pointer Arrays
5.1.5 Multidimensional Arrays
5.2 Pointers to Pointers
5.3 Linked Lists
5.3.1 Dynamically Allocated Pointers
5.3.2 Singly Linked Lists
5.3.3 Unconditional Construction
5.3.4 Traversal
5.3.5 Conditional Construction
5.3.6 Insertion
5.3.7 Deletion
5.3.8 Deallocation
5.3.9 Other Structures
5.4 Mysterious Memory Corruption
5.5 Summary
5.6 Key Terms
5.7 Exercises
5.7.1 Conceptual Review
5.7.2 Trace/Analysis
5.7.3 Programming Exercises
6. Function Scope
6.1 Recursion
6.1.1 Function Call Overhead
6.1.2 Unbounded Recursion
6.1.3 Local Memory Allocation
6.1.4 Conversion to Iteration
6.2 Reentrance
6.2.1 A Private Stack for Reentrance
6.2.2 A Critical Section for Reentrance
6.3 Exceptions
6.4 Entering and Leaving Scopes
6.4.1 Leaving Scopes via break
6.4.2 Leaving Scopes via continue
6.4.3 Leaving Scopes via return
6.4.4 Leaving Scopes via goto
6.4.5 Leaving Scopes via an Exception
6.5 Summary
6.6 Key Terms
6.7 Exercises
6.7.1 Conceptual Review
6.7.2 Trace/Analysis
6.7.3 Programming Exercises
7. Scopes and Lifetimes
7.1 Object Lifetime
7.2 Lifetimes
7.2.1 Global and External Variables
7.2.2 File-scope Variables
7.2.3 Function Static Variables
7.2.4 Class Static Variables
7.2.5 Local Variables
7.2.6 Dynamic Allocation
7.3 Calling Conventions
7.3.1 Pass-by-Value
7.3.2 Pass-by-Reference
7.3.3 Return-by-Value
7.3.4 Return-by-Reference
7.4 Passing Pointers
7.5 Returning Pointers
7.6 Dynamic Object Lifetimes
7.7 Summary
7.8 Key Terms
7.9 Exercises
7.9.1 Conceptual Review
7.9.2 Trace/Analysis
7.9.3 Programming Exercises
8. Function Pointers
8.1 Background
8.1.1 Functions as Addresses
8.1.2 Storing the Address of a Function
8.1.3 Sample Application
8.2 Function Pointers
8.2.1 Definition
8.2.2 A Classic Example
8.3 Callbacks
8.3.1 Definition
8.3.2 Visitor Pattern
8.3.3 Example
8.3.4 Calling Functions and Returning Function Pointers
8.4 Delegation: The Command Pattern
8.5 Functors
8.6 Arrays of Function Pointers
8.7 Non-Object-Oriented Polymorphism
8.8 Summary
8.9 Key Terms
8.10 Exercises
8.10.1 Conceptual Review
8.10.2 Trace/Analysis
8.10.3 Programming Exercises
9. Object-oriented Programming
9.1 Operator-Overloading
9.1.1 Friends
9.1.2 Overloaded Assignment
9.1.3 Private Operators
9.2 Inheritance
9.2.1 Subtyping
9.2.2 Contraction
9.2.3 Accessibility
9.3 Polymorphism
9.3.1 Overridden Functions in Java and C++
9.3.2 Heterogeneous Collections
9.3.3 Virtual Functions
9.3.4 Static Type-Checking and dynamic_cast
9.3.5 Static versus Dynamic Binding
9.4 Implementation of Polymorphism
9.4.1 Virtual Function Table
9.4.2 Overhead
9.4.3 Overloaded Virtual Assignment
9.5 Virtual Destructors
9.6 Abstract Classes
9.7 Containment
9.8 Multiple Inheritance
9.8.1 Ambiguity
9.8.2 Redundancy
9.8.3 The Observer Pattern
9.8.4 Object Layout for Multiple Inheritance
9.9 Summary
9.10 Key Terms
9.11 Exercises
9.12.1 Conceptual Review
9.12.2 Trace/Analysis
9.11.3 Programming Exercises
10. Ownership
10.1 The Object Ownership Model
10.1.1 Unshared Ownership
10.1.2 Shared Ownership
10.1.3 Java
10.1.4 References in C++
10.2 Pointers in C++
10.2.1 Specifying the Primary Handle
10.2.2 Retaining Ownership
10.2.3 Transferring Ownership
10.3 Auto-Pointers
10.4 Reference-Counting
10.4.1 The Object Container
10.4.2 The Reference Objects
10.4.3 A Sample Use
10.5 Smart Pointers
10.5.1 The Rep Objects
10.5.2 The Handle Object
10.6 Garbage Collection
10.6.1 A C++ Implementation
10.6.2 The List of Object Containers
10.6.3 The Object Container
10.6.4 Collect-Once Garbage Collection
10.6.5 The Object Reference Set
10.6.6 The Reference Objects
10.6.7 A Sample Use
10.6.8 Circular References
10.7 Summary
10.8 Key Terms
Appendix
A
Library Usage Examples
Appendix B auto_ptr
Appendix C Programming Environment
Appendix D Two-Tiered Type Checking Using Double Dispatch