Sams Teach Yourself C++ in 24 Hours, Second Edition
(Publisher: Macmillan Computer Publishing)
Author(s): Jesse Liberty
ISBN: 0672315165
Publication Date: 02/19/99

Introduction
About the Author

Part I—Introducing C++
Chapter1—Getting Started
Why C++ Is the Right Choice
Procedural, Structured, and Object-Oriented Programming
C++ and Object-Oriented Programming
Encapsulation and Data Hiding
Inheritance and Reuse
Polymorphism
How C++ Evolved
C++ Isn’t Just a Better C
Should I Learn C First?
Preparing to Program
C++, ANSI C++, Windows, and Other Areas of Confusion
Your Compiler and Editor
Compiling and Linking the Source Code
Compiling in an Integrated Development Environment
Linking Your Program
The Development Cycle
HELLO.CPP—Your First C++ Program
Compile Errors
Summary
Q&A
Chapter 2—The Parts of a C++ Program
The Parts of a Simple Program
Examining the #include, Character by Character
Line by Line Analysis
Comments
Types of Comments
Using Comments
Functions
Using Functions
Summary
Q & A
Chapter 3—Variables and Constants
What Is a Variable?
Setting Aside Memory
Size of Integers
signed and unsigned
Fundamental Variable Types
Defining a Variable
Case Sensitivity
Keywords
Creating More Than One Variable at a Time
Assigning Values to Your Variables
typedef
When to Use short and When to Use long
Wrapping Around in unsigned Integers
Wrapping Around a signed Integer
Constants
Literal Constants
Symbolic Constants
Defining Constants with #define
Defining Constants with const
Enumerated Constants
Summary
Q&A
Chapter 4—Expressions and Statements
Statements
Whitespace
Compound Statements
Expressions
Operators
Assignment Operator
Mathematical Operators
Combining the Assignment and Mathematical Operators
Increment and Decrement
Prefix and Postfix
Precedence
Nesting Parentheses
The Nature of Truth
Relational Operators
Relational Operators
The if Statement
The else Clause
Advanced if Statements
Use Braces in Nested if Statements
Logical Operators
Logical AND
Logical OR
Logical NOT
Relational Precedence
More About Truth and Falsehood
Summary
Q&A
Chapter 5—Functions
What Is a Function?
Declaring and Defining Functions
Declaring the Function
Defining the Function
Functions
Local Variables
Global Variables
Function Statements
Function Arguments
Using Functions as Parameters to Functions
Parameters Are Local Variables
Return Values
Default Parameters
Overloading Functions
Inline Functions
How Functions WorkA Look Under the Hood
The Stack
Summary
Q&A


Part II—Classes
Chapter 6—Basic Classes
Creating New Types
What Is a Type?
Why Create a New Type?
Classes and Members
Declaring a Class
A Word on Naming Conventions
Defining an Object
Classes Versus Objects
Accessing Class Members
Assign to Objects, Not to Classes
Private Versus Public
Make Member Data Private
Implementing Class Methods
Constructors and Destructors
Default Constructors
Constructors Provided by the Compiler
Summary
Q&A
Chapter 7—More About Classes
const Member Functions
Interface Versus Implementation
Where to Put Class Declarations and Method Definitions
Put Class Declarations in Header Files
Inline Implementation
Classes with Other Classes as Member Data
Summary
Q&A
Chapter 8—Advanced Program Flow
Looping
The Roots of Looping goto
Why goto Isn’t Used
while Loops
More Complicated while Statements
continue and break
while(1) Loops
do...while Loops
for Loops
Advanced for Loops
Multiple Initialization and Increments
null Statements in for Loops
Empty for Loops
Nested Loops
switch Statements
Summary
Q&A

Part III—Memory Management
Chapter 9—Pointers
What Is a Pointer?
Storing the Address in a Pointer
Pointer Names
The Indirection Operator
Pointers, Addresses, and Variables
Manipulating Data by Using Pointers
Examining the Address
Why Would You Use Pointers?
The Stack and the Free Store
new
delete
Memory Leaks
Summary
Q&A
Chapter 10—Advanced Pointers
Creating Objects on the Free Store
Deleting Objects
Accessing Data Members
Member Data on the Free Store
The this Pointer
What’s the this Pointer For?
Stray or Dangling Pointers
const Pointers
const Pointers and const Member Functions
const this Pointers
Summary
Q&A
Chapter 11—References
What Is a Reference?
Creating a Reference
Using the Address of Operator on References
What Can Be Referenced?
Null Pointers and Null References
Passing Function Arguments by Reference
Making swap() Work with Pointers
Implementing swap() with References
Understanding Function Headers and Prototypes
Returning Multiple Values
Returning Values by Reference
Summary
Q&A
Chapter 12—Advanced References and Pointers
Passing by Reference for Efficiency
Passing a const Pointer
References as an Alternative
When to Use References and When to Use Pointers
Don’t Return a Reference to an Object that Isn’t in Scope!
Returning a Reference to an Object on the Heap
Pointer, Pointer, Who Has the Pointer?
Summary
Q&A

Part IV—Power Tools
Chapter 13—Advanced Functions
Overloaded Member Functions
Using Default Values
Choosing Between Default Values and Overloaded Functions
The Default Constructor
Overloading Constructors
Initializing Objects
The Copy Constructor
Summary
Q&A
Chapter 14—Operator Overloading
Operator Overloading
Writing an Increment Function
Overloading the Postfix Operator
The Difference Between Prefix and Postfix
operator+
Overloading operator+
Limitations on Operator Overloading
What to Overload
operator=
Conversion Operators
The int() Operator
Summary
Q&A
Chapter 15—Arrays
What Is an Array?
Array Elements
Writing Past the End of an Array
Fence Post Errors
Initializing Arrays
Arrays of Objects
Multidimensional Arrays
Initializing Multidimensional Arrays
A Word About Memory
Arrays of Pointers
Declaring Arrays on the Free Store
A Pointer to an Array Versus an Array of Pointers
Pointers and Array Names
Deleting Arrays on the Free Store
char Arrays
strcpy() and strncpy()
String Classes
Summary
Q&A

Part V—Inheritance and Polymorphism
Chapter 16—Inheritance
What Is Inheritance?
Inheritance and Derivation
The Animal Kingdom
The Syntax of Derivation
Private versus Protected
Constructors and Destructors
Passing Arguments to Base Constructors
Overriding Functions
Overloading Versus Overriding
Hiding the Base Class Method
Calling the Base Method
Summary
Q&A
Chapter 17—Polymorphism and Derived Classes
Virtual Methods
How Virtual Member Functions Work
You Can’t Get There from Here
Slicing
Virtual Destructors
Virtual Copy Constructors
The Cost of Virtual Methods
Summary
Q&A
Chapter 18—Advanced Polymorphism
Problems with Single Inheritance
Abstract Data Types
Pure Virtual Functions
Implementing Pure Virtual Functions
Complex Hierarchies of Abstraction
Which Types Are Abstract?
Summary
Q&A
Chapter 19—Linked Lists
Linked Lists and Other Structures
A Case Study
Delegation of Responsibility
The Component Parts
What Have You Learned, Dorothy?
Summary
Q&A

Part VI—Special Topics
Chapter 20—Special Classes and Functions
Static Member Data
Static Member Functions
Containment
Accessing Members of the Contained Class
Filtering Access to Contained Members
The Cost of Containment
Copying by Value Versus by Reference
Friend Classes
Friend Functions
Pointers to Functions
Shorthand Invocation
Arrays of Pointers to Functions
Passing Pointers to Functions to Other Functions
Using typedef with Pointers to Functions
Arrays of Pointers to Member Functions
Summary
Q&A
Chapter 21—The Preprocessor
The Preprocessor and the Compiler
Seeing the Intermediate Form
Using #define
Using #define for Constants
Using #define for Tests
The #else Precompiler Command
Inclusion and Inclusion Guards
Defining on the Command Line
Undefining
Conditional Compilation
Macro Functions
Why All the Parentheses?
Macros Versus Functions and Templates
String Manipulation
Stringizing
Concatenation
Predefined Macros
assert()
Debugging with assert()
Side Effects
Class Invariants
Printing Interim Values
Debugging Levels
Summary
Q&A

Part VII—Advanced Topics
Chapter 22—Object-Oriented Analysis and Design
The Development Cycle
Simulating an Alarm System
Conceptualization
Analysis and Requirements
High-Level and Low-Level Design
Other Objects
What Are the Classes?
How Are Alarms Reported?
Event Loops
PostMaster: A Case Study
Measure Twice, Cut Once
Divide and Conquer
Message Format
Initial Class Design
Rooted Hierarchies Versus Non-Rooted
Designing the Interfaces
Building a Prototype
The 80/80 Rule
Designing the PostMasterMessage Class
The Application Programming Interface
Programming in Large Groups
Ongoing Design Considerations
Design Decisions
Decisions, Decisions
Working with Driver Programs
Summary
Q&A
Chapter 23—Templates
What Are Templates?
Parameterized Types
Template Definition
Using Template Items
The Standard Template Library
Summary
Q&A
Chapter 24—Exceptions and Error Handling
Bugs, Errors, Mistakes, and Code Rot
Handling the Unexpected
Exceptions
How Exceptions Are Used
Using try Blocks and catch Blocks
Catching Exceptions
More than One catch Specification
Catching by Reference and Polymorphism
Next Steps
Style
Braces
Long Lines
switch Statements
Program Text
Identifier Names
Spelling and Capitalization of Names
Comments
Access
Class Definitions
include Files
assert()
const
Next Steps
Where to Get Help and Advice
Required Reading
Magazines
Staying in Touch

Part VIII—Appendixes
Appendix A
Appendix B
Appendix C
Appendix D
Index