| |
| |
Introduction | |
| |
| |
| |
At a Glance | |
| |
| |
| |
Getting Started | |
| |
| |
Introduction | |
| |
| |
A Brief History of C++ | |
| |
| |
How C++ Evolved | |
| |
| |
Should I Learn C First? | |
| |
| |
C++ and Java and C# | |
| |
| |
The ANSI Standard | |
| |
| |
Preparing to Program | |
| |
| |
Your Development Environment | |
| |
| |
Creating the Program | |
| |
| |
The Development Cycle | |
| |
| |
HELLO.cpp--Your First C++ Program | |
| |
| |
Getting Started with Your Compiler | |
| |
| |
Compile Errors | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
The Anatomy of a C++ Program | |
| |
| |
A Simple Program | |
| |
| |
A Brief Look at cout | |
| |
| |
Using the Standard Namespace | |
| |
| |
Comments | |
| |
| |
Functions | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Variables and Constants | |
| |
| |
What Is a Variable? | |
| |
| |
Defining a Variable | |
| |
| |
Creating More Than One Variable at a Time | |
| |
| |
Assigning Values to Your Variables | |
| |
| |
typedef | |
| |
| |
When to Use short and When to Use long | |
| |
| |
Characters | |
| |
| |
Constants | |
| |
| |
Enumerated Constants | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Expressions and Statements | |
| |
| |
Statements | |
| |
| |
Expressions | |
| |
| |
Operators | |
| |
| |
Combining the Assignment and Mathematical Operators | |
| |
| |
Increment and Decrement | |
| |
| |
Precedence | |
| |
| |
Nesting Parentheses | |
| |
| |
The Nature of Truth | |
| |
| |
The if Statement | |
| |
| |
Using Braces in Nested if Statements | |
| |
| |
Logical Operators | |
| |
| |
Short Circuit Evaluation | |
| |
| |
Relational Precedence | |
| |
| |
More About Truth and Falsehood | |
| |
| |
Conditional (Ternary) Operator | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Functions | |
| |
| |
What Is a Function? | |
| |
| |
Return Values, Parameters, and Arguments | |
| |
| |
Declaring and Defining Functions | |
| |
| |
Execution of Functions | |
| |
| |
Local Variables | |
| |
| |
Global Variables | |
| |
| |
Global Variables: A Word of Caution | |
| |
| |
More on Local Variables | |
| |
| |
Function Statements | |
| |
| |
More About Function Arguments | |
| |
| |
Parameters Are Local Variables | |
| |
| |
More About Return Values | |
| |
| |
Default Parameters | |
| |
| |
Overloading Functions | |
| |
| |
Special Topics About Functions | |
| |
| |
How Functions Work--A Peek Under the Hood | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Object-Oriented Programming | |
| |
| |
Is C++ Object-Oriented? | |
| |
| |
Creating New Types | |
| |
| |
Classes and Members | |
| |
| |
Accessing Class Members | |
| |
| |
Private Versus Public | |
| |
| |
Implementing Class Methods | |
| |
| |
Constructors and Destructors | |
| |
| |
const Member Functions | |
| |
| |
Interface Versus Implementation | |
| |
| |
Where to Put Class Declarations and Method Definitions | |
| |
| |
Inline Implementation | |
| |
| |
Classes with Other Classes as Member Data | |
| |
| |
Structures | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
More Program Flow | |
| |
| |
Looping | |
| |
| |
while Loops | |
| |
| |
do...while Loops | |
| |
| |
do...while | |
| |
| |
for Loops | |
| |
| |
Summing Up Loops | |
| |
| |
switch Statements | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
In Review | |
| |
| |
| |
At a Glance | |
| |
| |
| |
Pointers | |
| |
| |
What Is a Pointer? | |
| |
| |
Why Would You Use Pointers? | |
| |
| |
The Stack and the Free Store (Heap) | |
| |
| |
Memory Leaks | |
| |
| |
Creating Objects on the Free Store | |
| |
| |
Deleting Objects | |
| |
| |
Accessing Data Members | |
| |
| |
Member Data on the Free Store | |
| |
| |
The this Pointer | |
| |
| |
Stray, Wild, or Dangling Pointers | |
| |
| |
const Pointers | |
| |
| |
Pointer Arithmetic--An Advanced Topic | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
References | |
| |
| |
What Is a Reference? | |
| |
| |
Using the Address Of Operator and on References | |
| |
| |
What Can Be Referenced? | |
| |
| |
Null Pointers and Null References | |
| |
| |
Passing Function Arguments by Reference | |
| |
| |
Understanding Function Headers and Prototypes | |
| |
| |
Returning Multiple Values | |
| |
| |
Passing by Reference for Efficiency | |
| |
| |
When to Use References and When to Use Pointers | |
| |
| |
Mixing References and 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 | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
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 | |
| |
| |
Operator Overloading | |
| |
| |
Handling Data Type Conversion | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Object-Oriented Analysis and Design | |
| |
| |
Building Models | |
| |
| |
Software Design: The Modeling Language | |
| |
| |
Software Design: The Process | |
| |
| |
Extreme Programming | |
| |
| |
The Vision | |
| |
| |
Requirements Analysis | |
| |
| |
Design | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Inheritance | |
| |
| |
What Is Inheritance? | |
| |
| |
Private Versus Protected | |
| |
| |
Constructors and Destructors | |
| |
| |
Overriding Functions | |
| |
| |
Virtual Methods | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Arrays and Linked Lists | |
| |
| |
What Is an Array? | |
| |
| |
Array Elements | |
| |
| |
Writing Past the End of an Array | |
| |
| |
Fence Post Errors | |
| |
| |
Initializing Arrays | |
| |
| |
Declaring 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 | |
| |
| |
Linked Lists and Other Structures | |
| |
| |
A Linked List Case Study | |
| |
| |
The Component Parts | |
| |
| |
What Have You Learned, Dorothy? | |
| |
| |
Array Classes | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Polymorphism | |
| |
| |
Problems with Single Inheritance | |
| |
| |
Multiple Inheritance | |
| |
| |
Abstract Data Types | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
In Review | |
| |
| |
| |
At a Glance | |
| |
| |
| |
Special Classes and Functions | |
| |
| |
Static Member Data | |
| |
| |
Static Member Functions | |
| |
| |
Pointers to Functions | |
| |
| |
Pointers to Member Functions | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Advanced Inheritance | |
| |
| |
Containment | |
| |
| |
Implementation in Terms of Inheritance/ Containment Versus Delegation | |
| |
| |
Private Inheritance | |
| |
| |
Friend Classes | |
| |
| |
Friend Functions | |
| |
| |
Friend Functions and Operator Overloading | |
| |
| |
Overloading the Insertion Operator | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Streams | |
| |
| |
Overview of Streams | |
| |
| |
Streams and Buffers | |
| |
| |
Standard I/O Objects | |
| |
| |
Redirection | |
| |
| |
Input Using cin | |
| |
| |
Other Member Functions of cin | |
| |
| |
Output with cout | |
| |
| |
Related Functions | |
| |
| |
Manipulators, Flags, and Formatting Instructions | |
| |
| |
Streams Versus the printf() Function | |
| |
| |
File Input and Output | |
| |
| |
ofstream | |
| |
| |
Binary Versus Text Files | |
| |
| |
Command-Line Processing | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Namespaces | |
| |
| |
Getting Started | |
| |
| |
Functions and Classes Are Resolved by Name | |
| |
| |
Creating a Namespace | |
| |
| |
Using a Namespace | |
| |
| |
The using Keyword | |
| |
| |
The Namespace Alias | |
| |
| |
The Unnamed Namespace | |
| |
| |
The Standard Namespace std | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Templates | |
| |
| |
What Are Templates? | |
| |
| |
Parameterized Types | |
| |
| |
Template Definition | |
| |
| |
Template Functions | |
| |
| |
Templates and Friends | |
| |
| |
Using Template Items | |
| |
| |
The Standard Template Library | |
| |
| |
Containers | |
| |
| |
Understanding Sequence Containers | |
| |
| |
Stacks | |
| |
| |
Understanding Queues | |
| |
| |
Understanding Associative Containers | |
| |
| |
Algorithm Classes | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
Exceptions and Error Handling | |
| |
| |
Bugs, Errors, Mistakes, and Code Rot | |
| |
| |
Exceptions | |
| |
| |
Using try Blocks and catch Blocks | |
| |
| |
Data in Exceptions and Naming Exception Objects | |
| |
| |
Exceptions and Templates | |
| |
| |
Exceptions Without Errors | |
| |
| |
A Word About Code Rot | |
| |
| |
Bugs and Debugging | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
What's Next | |
| |
| |
The Preprocessor and the Compiler | |
| |
| |
Seeing the Intermediate Form | |
| |
| |
Using #define | |
| |
| |
Inclusion and Inclusion Guards | |
| |
| |
Macro Functions | |
| |
| |
Inline Functions | |
| |
| |
String Manipulation | |
| |
| |
Predefined Macros | |
| |
| |
assert() | |
| |
| |
Bit Twiddling | |
| |
| |
Style | |
| |
| |
Next Steps | |
| |
| |
Summary | |
| |
| |
QandA | |
| |
| |
Workshop | |
| |
| |
| |
In Review | |
| |
| |
Appendixes | |
| |
| |
| |
Binary and Hexadecimal | |
| |
| |
Other Bases | |
| |
| |
Around the Bases | |
| |
| |
Hexadecimal | |
| |
| |
| |
C++ Keywords | |
| |
| |
| |
Operator Precedence | |
| |
| |
| |
Answers | |
| |
| |
Index | |