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 IIntroducing C++
- Chapter1Getting 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++ Isnt 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.CPPYour First C++ Program
- Compile Errors
- Summary
- Q&A
- Chapter 2The 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 3Variables 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 4Expressions 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 5Functions
- 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 IIClasses
- Chapter 6Basic 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 7More 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 8Advanced Program Flow
- Looping
- The Roots of Looping goto
- Why goto Isnt 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 IIIMemory Management
- Chapter 9Pointers
- 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 10Advanced Pointers
- Creating Objects on the Free Store
- Deleting Objects
- Accessing Data Members
- Member Data on the Free Store
- The this Pointer
- Whats the this Pointer For?
- Stray or Dangling Pointers
- const Pointers
- const Pointers and const Member Functions
- const this Pointers
- Summary
- Q&A
- Chapter 11References
- 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 12Advanced 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
- Dont Return a Reference to an Object that Isnt in Scope!
- Returning a Reference to an Object on the Heap
- Pointer, Pointer, Who Has the Pointer?
- Summary
- Q&A
- Part IVPower Tools
- Chapter 13Advanced 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 14Operator 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 15Arrays
- 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 VInheritance and Polymorphism
- Chapter 16Inheritance
- 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 17Polymorphism and Derived Classes
- Virtual Methods
- How Virtual Member Functions Work
- You Cant Get There from Here
- Slicing
- Virtual Destructors
- Virtual Copy Constructors
- The Cost of Virtual Methods
- Summary
- Q&A
- Chapter 18Advanced 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 19Linked Lists
- Linked Lists and Other Structures
- A Case Study
- Delegation of Responsibility
- The Component Parts
- What Have You Learned, Dorothy?
- Summary
- Q&A
- Part VISpecial Topics
- Chapter 20Special 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 21The 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 VIIAdvanced Topics
- Chapter 22Object-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 23Templates
- What Are Templates?
- Parameterized Types
- Template Definition
- Using Template Items
- The Standard Template Library
- Summary
- Q&A
- Chapter 24Exceptions 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 VIIIAppendixes
Appendix A
Appendix B
Appendix C
Appendix D
Index