Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Cover
Title
Copyright
Dedication
Contents at a Glance
Contents
About the Author
Acknowledgments
Introduction
Chapter 1: Introduction to Objects
The Progress of Abstraction
An Object Has An Interface
The Hidden Implementation
Reusing the Implementation
Inheritance: Reusing the Interface
Is-a vs. is-like-a Relationships
Interchangeable Objects with Polymorphism
Creating and Destroying Objects
Exception Handling: Dealing with Errors
Analysis and Design
Phase 0: Make a Plan
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
Extreme Programming
Write Tests First
Pair Programming
Why C++ Succeeds
A Better C
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
Strategies for Transition
Guidelines
Management Obstacles
Review Session
Chapter 2: Making and Using Objects
The Process of Language Translation
Interpreters
Compilers
The Compilation Process
Static Type Checking
Tools for Separate Compilation
Declarations vs. Definitions
Function Declaration Syntax
Function Definitions
Variable Declaration Syntax
Including Headers
Standard C++ include Format
Linking
Using Libraries
How the Linker Searches a Library
Secret Additions
Using Plain C Libraries
Your First C++ Program
Using the iostream Class
Namespaces
Fundamentals of Program Structure
Running the Compiler
More About iostream
Character Array Concatenation
Reading Input
Calling Other Programs
Introducing Strings
Reading and Writing Files
Introducing Vector
Review Session
Chapter 3: The C in C++
Creating Functions
Function Return Values
Using the C Function Library
Creating Your Own Libraries with the Librarian
Controlling Execution
True and False
Using if-else
Using while
Using do-while
Using for
The break and continue Keywords
Using switch
Using and Misusing goto
Recursion
Introduction to Operators
Precedence
Auto-Increment and Auto-Decrement
Introduction to Data Types
Basic Built-in Types
Using bool, true, and false
Using Specifiers
Introduction to Pointers
Modifying the Outside Object
Introduction to C++ References
Pointers and References as Modifiers
Understanding Scoping
Defining Variables on the Fly
Specifying Storage Allocation
Global Variables
Local Variables
The static Keyword
The extern Keyword
Linkage
Constants
Constant Values
The volatile Qualifier
Operators and Their Use
Assignment
Mathematical Operators
Introduction to Preprocessor Macros
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
Composite Type Creation
Aliasing Names with typedef
Combining Variables with struct
Pointers and structs
Clarifying Programs with enum
Type Checking for Enumerations
Saving Memory with union
Using Arrays
Pointers and Arrays
Exploring Floating-Point Format
Pointer Arithmetic
Debugging Hints
Debugging Flags
Turning Variables and Expressions into Strings
The C assert( ) Macro
Function Addresses
Defining a Function Pointer
Complicated Declarations and Definitions
Using a Function Pointer
Arrays of Pointers to Functions
Make Activities
Macros
Suffix Rules
Default Targets
An Example makefile
The I/O System
Review Session
Chapter 4: Data Abstraction
A Tiny C-like Library
Dynamic Storage Allocation
Bad Guesses
What’s wrong?
The Basic Object
What’s an object?
Abstract Data Typing
Object Details
Header File Etiquette
Importance of Header Files
The Multiple-Declaration Problem
The Preprocessor Directives:#define, #ifdef, #endif
A Standard for Header Files
Namespaces in Headers
Using Headers in Projects
Nested Structures
Global Scope Resolution
Review Session
Chapter 5: Hiding the Implementation
Setting Limits
C++ Access Control
Another Access Specifier: protected
Friends
Nested Friends
Is it pure?
Object Layout
The Class
Modifying Stash to Use Access Control
Modifying Stack to Use Access Control
Handle Classes
Hiding the Implementation
Reducing Recompilation
Review Session
Chapter 6: Initialization and Cleanup
Guaranteed Initialization with the Constructor
Guaranteed Cleanup with the Destructor
Elimination of the Definition Block
for loops
Storage Allocation
Stash with Constructors and Destructors
Stack with Constructors and Destructors
Aggregate Initialization
Default Constructors
Review Session
Chapter 7: Function Overloading and Default Arguments
More Name Decoration
Overloading on Return Values
Type-Safe Linkage
Overloading Example
Unions
Default Arguments
Placeholder Arguments
Choosing Overloading vs. Default Arguments
Review Session
Chapter 8: Constants
Value Substitution
const in Header Files
Safety consts
Aggregates
Differences with C
Pointers
Pointer to const
const Pointer
Assignment and Type Checking
Character Array Literals
Function Arguments and Return Values
Passing by const Value
Returning by const Value
Temporaries
Passing and Returning Addresses
Standard Argument Passing
Classes
const in Classes
The Constructor Initializer List
“Constructors” for Built-in Types
Compile-Time Constants in Classes
The “enum hack” in Old Code
const Objects and Member Functions
Mutable: Bitwise vs. Logical const
ROMability
The volatile Keyword
Review Session
Chapter 9: Inline Functions
Preprocessor Pitfalls
Macros and Access
Inline Functions
Inlines Inside Classes
Access Functions
Accessors and Mutators
Stash and Stack with Inlines
Inlines and the Compiler
Limitations
Forward References
Hidden Activities in Constructors and Destructors
Reducing Clutter
More Preprocessor Features
Token Pasting
Improved Error Checking
Review Session
Chapter 10: Name Control
Static Elements from C
Static Variables Inside Functions
Static Class Objects Inside Functions
Static Object Destructors
Controlling Linkage
Confusion
Other Storage Class Specifiers
Namespaces
Creating a namespace
Unnamed Namespaces
Friends
Using a Namespace
The using Directive
The using Declaration
The Use of Namespaces
Static Members in C++
Defining Storage for Static Data Members
static Array Initialization
Nested and Local Classes
static Member Functions
Static Initialization Dependency
Solving the Problem
Alternate Linkage Specifications
Review Session
Chapter 11: References and the Copy Constructor
Pointers in C++
References in C++
References in Functions
const References
Pointer References
Argument-Passing Guidelines
The Copy-Constructor
Passing and Returning by Value
Passing and Returning Large Objects
Function-Call Stack Frame
Reentrancy
Bit-Copy vs. Initialization
Copy-Construction
Temporary Objects
Default Copy-Constructor
Alternatives to Copy-Construction
Pointers-to-Members
Functions
Review Session
Chapter 12: Operator Overloading
Warning and Reassurance
Syntax
Overloadable Operators
Unary Operators
Binary Operators
Arguments and Return Values
Return by Value as a const
The Return Optimization
Unusual Operators
Operator Comma
Operator->
A Nested Iterator
Operator->*
Operators You Can’t Overload
Non-Member Operators
Basic Guidelines
Overloading Assignment
Behavior of operator=
Pointers in Classes
Reference Counting
Automatic operator= Creation
Automatic Type Conversion
Constructor Conversion
Preventing Constructor Conversion
Operator Conversion
Reflexivity
Type Conversion Example
Pitfalls in Automatic Type Conversion
Hidden Activities
Review Session
Chapter 13: Dynamic Object Creation
Object Creation
C’s Approach to the Heap
Operator new
Operator delete
Memory Manager Overhead
Early Examples Redesigned
delete void* is Probably a Bug
Cleanup Responsibility with Pointers
Stash for Pointers
A Test
Using new and delete for Arrays
Making a Pointer More Like an Array
Running Out of Storage
Overloading new and delete
Overloading Global new and delete
Overloading new and delete for a Class
Overloading new and delete for Arrays
Constructor Calls
Placing new and delete
Review Session
Chapter 14: Inheritance and Composition
Composition Syntax
Inheritance Syntax
The Constructor Initializer List
Member Object Initialization
Built-in Types in the Initializer List
Combining Composition and Inheritance
Automatic Destructor Calls
Order of Constructor and Destructor Calls
Name Hiding
Functions That Don’t Automatically Inherit
Inheritance and Static Member Functions
Choosing Composition vs. Inheritance
Subtyping
private Inheritance
Publicizing Privately Inherited Members
The protected Keyword
protected Inheritance
Operator Overloading and Inheritance
Multiple Inheritance
Incremental Development
Upcasting
Why “upcasting?”
Upcasting and the copy-constructor
Composition vs. Inheritance (Revisited)
Pointer and Reference Upcasting
A Crisis
Review Session
Chapter 15: Polymorphism and Virtual Functions
Evolution of C++ Programmers
Upcasting
The Problem
Function Call Binding
Using Virtual Functions
Extensibility
How C++ Implements Late Binding
Storing Type Information
Picturing Virtual Functions
Under the Hood
Installing the Vpointer
Objects Are Different
Why virtual functions?
Abstract Base Classes and Pure Virtual Functions
Pure Virtual Definitions
Inheritance and the VTABLE
Object Slicing
Overloading and Overriding
Variant Return Type
Virtual Functions and Constructors
Order of Constructor Calls
Behavior of Virtual Functions Inside Constructors
Destructors and Virtual Destructors
Pure Virtual Destructors
Virtuals in Destructors
Creating an Object-Based Hierarchy
Operator Overloading
Downcasting
Review Session
Chapter 16: Introduction to Templates
Containers
The Need for Containers
Overview of Templates
The C Solution
The Smalltalk Solution
The Template Solution
Template Syntax
Non-Inline Function Definitions
Header Files
IntStack as a Template
Constants in Templates
Stack and Stash as Templates
Templatized pointer Stash
Turning Ownership On and Off
Holding Objects by Value
Introducing Iterators
Stack with Iterators
PStash with Iterators
Why iterators?
Function Templates
Review Session
Chapter 17: Exception Handling
Traditional Error Handling
Throwing an Exception
Catching an Exception
The try Block
Exception Handlers
Termination and Resumption
Exception Matching
Catching Any Exception
Rethrowing an Exception
Uncaught Exceptions
Cleaning Up
Resource Management
Making Everything an Object
Using auto_ptr
Function–Level try Blocks
Standard Exceptions
Exception Specifications
The unexpected( ) Function
The set_unexpected( ) Function
Better Exception Specifications?
Exception Specifications and Inheritance
When Not to Use Exception Specifications
Exception Safety
Programming with Exceptions
When to Avoid Exceptions
Typical Uses of Exceptions
Overhead
Review Session
Chapter 18: Strings in Depth
What’s in a string?
Creating and Initializing C++ Strings
Operating on Strings
Appending, Inserting, and Concatenating Strings
Replacing String Characters
Simple Character Replacement Using the STL replace() Algorithm
Concatenation Using Nonmember Overloaded Operators
Searching in Strings
Finding in Reverse
Finding First/Last of a Set of Characters
Removing Characters from Strings
Comparing Strings
Strings and Character Traits
A String Application
Review Session
Chapter 19: iostreams
Why iostreams?
iostreams to the Rescue
Inserters and Extractors
Common Usage
Line–Oriented Input
Overloaded Versions of get( )
Reading Raw Bytes
Handling Stream Errors
Stream State
Streams and Exceptions
File iostreams
A File–Processing Example
Open Modes
iostream Buffering
Seeking in iostreams
String iostreams
Input String Streams
Output string streams
Output Stream Formatting
Format Flags
Format Fields
Width, Fill, and Precision
An Exhaustive Example
Manipulators
Manipulators with Arguments
Creating Manipulators
Effectors
iostream Examples
Maintaining Class Library Source Code
Detecting Compiler Errors
A Simple Data Logger
Generating Test Data
Verifying and Viewing the Data
Internationalization
Wide Streams
Locales
Review Session
Chapter 20: Runtime Type Identification (RTTI)
Runtime Casts
The typeid Operator
Casting to Intermediate Levels
void Pointers
Using RTTI with Templates
Multiple Inheritance
Sensible Uses for RTTI
A Trash Recycler
Mechanism and Overhead of RTTI
Review Session
Chapter 21: Multiple Inheritance (MI)
Perspective
Interface Inheritance
Implementation Inheritance
Duplicate Subobjects
Virtual Base Classes
Name Lookup Issues
Avoiding MI
Extending an Interface
Review Session
Index
← Prev
Back
Next →
← Prev
Back
Next →