Contents

Preface

Chapter 1. Getting Started

1.1 Writing a Simple C++ Program

1.1.1 Compiling and Executing Our Program

1.2 A First Look at Input/Output

1.2.1 Standard Input and Output Objects

1.2.2 A Program that Uses the IO Library

1.3 A Word About Comments

1.4 Control Structures

1.4.1 The while Statement

1.4.2 The for Statement

1.4.3 The if Statement

1.4.4 Reading an Unknown Number of Inputs

1.5 Introducing Classes

1.5.1 The Sales_item Class

1.5.2 A First Look at Member Functions

1.6 The C++ Program

Chapter Summary

Defined Terms

Part I. The Basics

Chapter 2. Variables and Basic Types

2.1 Primitive Built-in Types

2.1.1 Integral Types

2.1.2 Floating-Point Types

2.2 Literal Constants

2.3 Variables

2.3.1 What Is a Variable?

2.3.2 The Name of a Variable

2.3.3 Defining Objects

2.3.4 Variable Initialization Rules

2.3.5 Declarations and Definitions

2.3.6 Scope of a Name

2.3.7 Define Variables Where They Are Used

2.4 const Qualifier

2.5 References

2.6 Typedef Names

2.7 Enumerations

2.8 Class Types

2.9 Writing Our Own Header Files

2.9.1 Designing Our Own Headers

2.9.2 A Brief Introduction to the Preprocessor

Chapter Summary

Defined Terms

Chapter 3. Library Types

3.1 Namespace using Declarations

3.2 Library string Type

3.2.1 Defining and Initializing strings

3.2.2 Reading and Writing strings

3.2.3 Operations on strings

3.2.4 Dealing with the Characters of a string

3.3 Library vector Type

3.3.1 Defining and Initializing vectors

3.3.2 Operations on vectors

3.4 Introducing Iterators

3.4.1 Iterator Arithmetic

3.5 Library bitset Type

3.5.1 Defining and Initializing bitsets

3.5.2 Operations on bitsets

Chapter Summary

Defined Terms

Chapter 4. Arrays and Pointers

4.1 Arrays

4.1.1 Defining and Initializing Arrays

4.1.2 Operations on Arrays

4.2 Introducing Pointers

4.2.1 What Is a Pointer?

4.2.2 Defining and Initializing Pointers

4.2.3 Operations on Pointers

4.2.4 Using Pointers to Access Array Elements

4.2.5 Pointers and the const Qualifier

4.3 C-Style Character Strings

4.3.1 Dynamically Allocating Arrays

4.3.2 Interfacing to Older Code

4.4 Multidimensioned Arrays

4.4.1 Pointers and Multidimensioned Arrays

Chapter Summary

Defined Terms

Chapter 5. Expressions

5.1 Arithmetic Operators

5.2 Relational and Logical Operators

5.3 The Bitwise Operators

5.3.1 Using bitset Objects or Integral Values

5.3.2 Using the Shift Operators for IO

5.4 Assignment Operators

5.4.1 Assignment Is Right Associative

5.4.2 Assignment Has Low Precedence

5.4.3 Compound Assignment Operators

5.5 Increment and Decrement Operators

5.6 The Arrow Operator

5.7 The Conditional Operator

5.8 The sizeof Operator

5.9 Comma Operator

5.10 Evaluating Compound Expressions

5.10.1 Precedence

5.10.2 Associativity

5.10.3 Order of Evaluation

5.11 The new and delete Expressions

5.12 Type Conversions

5.12.1 When Implicit Type Conversions Occur

5.12.2 The Arithmetic Conversions

5.12.3 Other Implicit Conversions

5.12.4 Explicit Conversions

5.12.5 When Casts Might Be Useful

5.12.6 Named Casts

5.12.7 Old-Style Casts

Chapter Summary

Defined Terms

Chapter 6. Statements

6.1 Simple Statements

6.2 Declaration Statements

6.3 Compound Statements (Blocks)

6.4 Statement Scope

6.5 The if Statement

6.5.1 The if Statement else Branch

6.6 The switch Statement

6.6.1 Using a switch

6.6.2 Control Flow within a switch

6.6.3 The default Label

6.6.4 switch Expression and Case Labels

6.6.5 Variable Definitions inside a switch

6.7 The while Statement

6.8 The for Loop Statement

6.8.1 Omitting Parts of the for Header

6.8.2 Multiple Definitions in the for Header

6.9 The do while Statement

6.10 The break Statement

6.11 The continue Statement

6.12 The goto Statement

6.13 try Blocks and Exception Handling

6.13.1 A throw Expression

6.13.2 The try Block

6.13.3 Standard Exceptions

6.14 Using the Preprocessor for Debugging

Chapter Summary

Defined Terms

Chapter 7. Functions

7.1 Defining a Function

7.1.1 Function Return Type

7.1.2 Function Parameter List

7.2 Argument Passing

7.2.1 Nonreference Parameters

7.2.2 Reference Parameters

7.2.3 vector and Other Container Parameters

7.2.4 Array Parameters

7.2.5 Managing Arrays Passed to Functions

7.2.6 main: Handling Command-Line Options

7.2.7 Functions with Varying Parameters

7.3 The return Statement

7.3.1 Functions with No Return Value

7.3.2 Functions that Return a Value

7.3.3 Recursion

7.4 Function Declarations

7.4.1 Default Arguments

7.5 Local Objects

7.5.1 Automatic Objects

7.5.2 Static Local Objects

7.6 Inline Functions

7.7 Class Member Functions

7.7.1 Defining the Body of a Member Function

7.7.2 Defining a Member Function Outside the Class

7.7.3 Writing the Sales_item Constructor

7.7.4 Organizing Class Code Files

7.8 Overloaded Functions

7.8.1 Overloading and Scope

7.8.2 Function Matching and Argument Conversions

7.8.3 The Three Steps in Overload Resolution

7.8.4 Argument-Type Conversions

7.9 Pointers to Functions

Chapter Summary

Defined Terms

Chapter 8. The IO Library

8.1 An Object-Oriented Library

8.2 Condition States

8.3 Managing the Output Buffer

8.4 File Input and Output

8.4.1 Using File Stream Objects

8.4.2 File Modes

8.4.3 A Program to Open and Check Input Files

8.5 String Streams

Chapter Summary

Defined Terms

Part II. Containers and Algorithms

Chapter 9. Sequential Containers

9.1 Defining a Sequential Container

9.1.1 Initializing Container Elements

9.1.2 Constraints on Types that a Container Can Hold

9.2 Iterators and Iterator Ranges

9.2.1 Iterator Ranges

9.2.2 Some Container Operations Invalidate Iterators

9.3 Sequence Container Operations

9.3.1 Container Typedefs

9.3.2 begin and end Members

9.3.3 Adding Elements to a Sequential Container

9.3.4 Relational Operators

9.3.5 Container Size Operations

9.3.6 Accessing Elements

9.3.7 Erasing Elements

9.3.8 Assignment and swap

9.4 How a vector Grows

9.4.1 capacity and reserve Members

9.5 Deciding Which Container to Use

9.6 strings Revisited

9.6.1 Other Ways to Construct strings

9.6.2 Other Ways to Change a string

9.6.3 string-Only Operations

9.6.4 string Search Operations

9.6.5 Comparing strings

9.7 Container Adaptors

9.7.1 Stack Adaptor

9.7.2 Queue and Priority Queue

Chapter Summary

Defined Terms

Chapter 10. Associative Containers

10.1 Preliminaries: the pair Type

10.2 Associative Containers

10.3 The map Type

10.3.1 Defining a map

10.3.2 Types Defined by map

10.3.3 Adding Elements to a map

10.3.4 Subscripting a map

10.3.5 Using map::insert

10.3.6 Finding and Retrieving a map Element

10.3.7 Erasing Elements from a map

10.3.8 Iterating across a map

10.3.9 A Word Transformation Map

10.4 The set Type

10.4.1 Defining and Using sets

10.4.2 Building a Word-Exclusion Set

10.5 The multimap and multiset Types

10.5.1 Adding and Removing Elements

10.5.2 Finding Elements in a multimap or multiset

10.6 Using Containers: Text-Query Program

10.6.1 Design of the Query Program

10.6.2 TextQuery Class

10.6.3 Using the TextQuery Class

10.6.4 Writing the Member Functions

Chapter Summary

Defined Terms

Chapter 11. Generic Algorithms

11.1 Overview

11.2 A First Look at the Algorithms

11.2.1 Read-Only Algorithms

11.2.2 Algorithms that Write Container Elements

11.2.3 Algorithms that Reorder Container Elements

11.3 Revisiting Iterators

11.3.1 Insert Iterators

11.3.2 iostream Iterators

11.3.3 Reverse Iterators

11.3.4 const Iterators

11.3.5 The Five Iterator Categories

11.4 Structure of Generic Algorithms

11.4.1 Algorithm Parameter Patterns

11.4.2 Algorithm Naming Conventions

11.5 Container-Specific Algorithms

Chapter Summary

Defined Terms

Part III. Classes and Data Abstraction

Chapter 12. Classes

12.1 Class Definitions and Declarations

12.1.1 Class Definitions: A Recap

12.1.2 Data Abstraction and Encapsulation

12.1.3 More on Class Definitions

12.1.4 Class Declarations versus Definitions

12.1.5 Class Objects

12.2 The Implicit this Pointer

12.3 Class Scope

12.3.1 Name Lookup in Class Scope

12.4 Constructors

12.4.1 The Constructor Initializer

12.4.2 Default Arguments and Constructors

12.4.3 The Default Constructor

12.4.4 Implicit Class-Type Conversions

12.4.5 Explicit Initialization of Class Members

12.5 Friends

12.6 static Class Members

12.6.1 static Member Functions

12.6.2 static Data Members

Chapter Summary

Defined Terms

Chapter 13. Copy Control

13.1 The Copy Constructor

13.1.1 The Synthesized Copy Constructor

13.1.2 Defining Our Own Copy Constructor

13.1.3 Preventing Copies

13.2 The Assignment Operator

13.3 The Destructor

13.4 A Message-Handling Example

13.5 Managing Pointer Members

13.5.1 Defining Smart Pointer Classes

13.5.2 Defining Valuelike Classes

Chapter Summary

Defined Terms

Chapter 14. Overloaded Operations and Conversions

14.1 Defining an Overloaded Operator

14.1.1 Overloaded Operator Design

14.2 Input and Output Operators

14.2.1 Overloading the Output Operator <<

14.2.2 Overloading the Input Operator >>

14.3 Arithmetic and Relational Operators

14.3.1 Equality Operators

14.3.2 Relational Operators

14.4 Assignment Operators

14.5 Subscript Operator

14.6 Member Access Operators

14.7 Increment and Decrement Operators

14.8 Call Operator and Function Objects

14.8.1 Using Function Objects with Library Algorithms

14.8.2 Library-Defined Function Objects

14.8.3 Function Adaptors for Function Objects

14.9 Conversions and Class Types

14.9.1 Why Conversions Are Useful

14.9.2 Conversion Operators

14.9.3 Argument Matching and Conversions

14.9.4 Overload Resolution and Class Arguments

14.9.5 Overloading, Conversions, and Operators

Chapter Summary

Defined Terms

Part IV. Object-Oriented and Generic Programming

Chapter 15. Object-Oriented Programming

15.1 OOP: An Overview

15.2 Defining Base and Derived Classes

15.2.1 Defining a Base Class

15.2.2 protected Members

15.2.3 Derived Classes

15.2.4 virtual and Other Member Functions

15.2.5 Public, Private, and Protected Inheritance

15.2.6 Friendship and Inheritance

15.2.7 Inheritance and Static Members

15.3 Conversions and Inheritance

15.3.1 Derived-to-Base Conversions

15.3.2 Conversions from Base to Derived

15.4 Constructors and Copy Control

15.4.1 Base-Class Constructors and Copy Control

15.4.2 Derived-Class Constructors

15.4.3 Copy Control and Inheritance

15.4.4 Virtual Destructors

15.4.5 Virtuals in Constructors and Destructors

15.5 Class Scope under Inheritance

15.5.1 Name Lookup Happens at Compile Time

15.5.2 Name Collisions and Inheritance

15.5.3 Scope and Member Functions

15.5.4 Virtual Functions and Scope

15.6 Pure Virtual Functions

15.7 Containers and Inheritance

15.8 Handle Classes and Inheritance

15.8.1 A Pointerlike Handle

15.8.2 Cloning an Unknown Type

15.8.3 Using the Handle

15.9 Text Queries Revisited

15.9.1 An Object-Oriented Solution

15.9.2 A Valuelike Handle

15.9.3 The Query_base Class

15.9.4 The Query Handle Class

15.9.5 The Derived Classes

15.9.6 The eval Functions

Chapter Summary

Defined Terms

Chapter 16. Templates and Generic Programming

16.1 Template Definitions

16.1.1 Defining a Function Template

16.1.2 Defining a Class Template

16.1.3 Template Parameters

16.1.4 Template Type Parameters

16.1.5 Nontype Template Parameters

16.1.6 Writing Generic Programs

16.2 Instantiation

16.2.1 Template Argument Deduction

16.2.2 Function-Template Explicit Arguments

16.3 Template Compilation Models

16.4 Class Template Members

16.4.1 Class-Template Member Functions

16.4.2 Template Arguments for Nontype Parameters

16.4.3 Friend Declarations in Class Templates

16.4.4 Queue and QueueItem Friend Declarations

16.4.5 Member Templates

16.4.6 The Complete Queue Class

16.4.7 static Members of Class Templates

16.5 A Generic Handle Class

16.5.1 Defining the Handle Class

16.5.2 Using the Handle

16.6 Template Specializations

16.6.1 Specializing a Function Template

16.6.2 Specializing a Class Template

16.6.3 Specializing Members but Not the Class

16.6.4 Class-Template Partial Specializations

16.7 Overloading and Function Templates

Chapter Summary

Defined Terms

Part V. Advanced Topics

Chapter 17. Tools for Large Programs

17.1 Exception Handling

17.1.1 Throwing an Exception of Class Type

17.1.2 Stack Unwinding

17.1.3 Catching an Exception

17.1.4 Rethrow

17.1.5 The Catch-All Handler

17.1.6 Function Try Blocks and Constructors

17.1.7 Exception Class Hierarchies

17.1.8 Automatic Resource Deallocation

17.1.9 The auto_ptr Class

17.1.10 Exception Specifications

17.1.11 Function Pointer Exception Specifications

17.2 Namespaces

17.2.1 Namespace Definitions

17.2.2 Nested Namespaces

17.2.3 Unnamed Namespaces

17.2.4 Using Namespace Members

17.2.5 Classes, Namespaces, and Scope

17.2.6 Overloading and Namespaces

17.2.7 Namespaces and Templates

17.3 Multiple and Virtual Inheritance

17.3.1 Multiple Inheritance

17.3.2 Conversions and Multiple Base Classes

17.3.3 Copy Control for Multiply Derived Classes

17.3.4 Class Scope under Multiple Inheritance

17.3.5 Virtual Inheritance

17.3.6 Virtual Base Class Declaration

17.3.7 Special Initialization Semantics

Chapter Summary

Defined Terms

Chapter 18. Specialized Tools and Techniques

18.1 Optimizing Memory Allocation

18.1.1 Memory Allocation in C++

18.1.2 The allocator Class

18.1.3 operator new and operator delete Functions

18.1.4 Placement new Expressions

18.1.5 Explicit Destructor Invocation

18.1.6 Class Specific new and delete

18.1.7 A Memory-Allocator Base Class

18.2 Run-Time Type Identification

18.2.1 The dynamic_cast Operator

18.2.2 The typeid Operator

18.2.3 Using RTTI

18.2.4 The type_info Class

18.3 Pointer to Class Member

18.3.1 Declaring a Pointer to Member

18.3.2 Using a Pointer to Class Member

18.4 Nested Classes

18.4.1 A Nested-Class Implementation

18.4.2 Name Lookup in Nested Class Scope

18.5 Union: A Space-Saving Class

18.6 Local Classes

18.7 Inherently Nonportable Features

18.7.1 Bit-fields

18.7.2 volatile Qualifier

18.7.3 Linkage Directives: extern "C"

Chapter Summary

Defined Terms

Appendix A. The Library

A.1 Library Names and Headers

A.2 A Brief Tour of the Algorithms

A.2.1 Algorithms to Find an Object

A.2.2 Other Read-Only Algorithms

A.2.3 Binary-Search Algorithms

A.2.4 Algorithms that Write Container Elements

A.2.5 Partitioning and Sorting Algorithms

A.2.6 General Reordering Operations

A.2.7 Permutation Algorithms

A.2.8 Set Algorithms for Sorted Sequences

A.2.9 Minimum and Maximum Values

A.2.10 Numeric Algorithms

A.3 The IO Library Revisited

A.3.1 Format State

A.3.2 Many Manipulators Change the Format State

A.3.3 Controlling Output Formats

A.3.4 Controlling Input Formatting

A.3.5 Unformatted Input/Output Operations

A.3.6 Single-Byte Operations

A.3.7 Multi-Byte Operations

A.3.8 Random Access to a Stream

A.3.9 Reading and Writing to the Same File

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset