C++ FAQs, 2/e (Paperback)
暫譯: C++ 常見問題解答,第2版 (平裝本)

Marshall P. Cline, Greg Lomow, Mike Girou

  • 出版商: Addison Wesley
  • 出版日期: 1998-12-21
  • 售價: $2,730
  • 貴賓價: 9.5$2,594
  • 語言: 英文
  • 頁數: 587
  • 裝訂: Paperback
  • ISBN: 0201309831
  • ISBN-13: 9780201309836
  • 相關分類: C++ 程式語言
  • 已絕版

買這商品的人也買了...

商品描述

 

Table Of Contents

Acknowledgments.

 

 

 

 

I. PRELIMINARIES.

 

 

 

1. Introduction.

 

What Is the Purpose of This Chapter?
What Are C++ FAQs?
Who Is the Target Audience for This Book?
Is This a Book about C++ Per Se?
Why Do Developers Need a Guidebook for C++ and OO Technology?
What Kind of Guidance Is Given in the Answers to These FAQs?
What Is the Electronic FAQ and Why Buy This Book When the Electronic FAQ Is Free?
Why Should You Buy This Edition if You Already Have a Copy of the First Edition?
What Conventions Are Used in This Book?


2. Basic C++ Syntax and Semantics.

 

What Is the Purpose of This Chapter?
What Are the Basics of Main()?
What Are the Basics of Functions?
What Are the Basics of Default Parameters?
What Are the Basics of Local (Auto) Objects?
What Are the Basics of Constructing Objects Using Explicit Parameters?
What Are the Basics of Dynamically Allocated (New) Objects?
What Are the Basics of Local Objects within Inner Scopes?
What Are the Basics of Passing Objects by Reference?
What Are the Basics of Passing Objects by Value?
What Are the Basics of Passing Objects by Pointer?
What Are the Basics of Stream Output?
What Are the Basics of Stream Input?
What Are the Basics of Using Classes That Contain Overloaded Operators?
What Are the Basics of Using Container Classes?
What Are the Basics of Creating Class Header Files?
What Are the Basics of Defining a Class?
What Are the Basics of Defining Member Functions?
What Are the Basics of Adding a Constructor to a Class?
What Are the Basics of Adding a Destructor to a Class?
What Are the Basics of Defining a Class That Contains a Pointer to an Object Allocated from the Heap?
What Are the Basics of Global Objects?
What Are the Basics of Throwing and Catching Exceptions?
What Are the Basics of Inheritance and Dynamic Binding?


3. Understanding the Management Perspective.

 

 

What Is the Purpose of This Chapter?
What Is the Core Message of This Chapter (and This Book)?
Why Are the Managers in Charge Rather Than the Developers Who Understand Technology?
How Can Someone Manage Something They Don't Understand?
What Is the Most Common Mistake on C++ and OO Projects?
What's the “Software Peter Principle?”
Should an Organization Use OO on All Its Projects?
Can OO Be Ignored Until It Goes Away?
What OO Language Is Best?
What Is the Right Approach to Processes and Tools?
What Is the Right Approach with Off-the-Shelf Class Libraries and Frameworks?


4. The Architectural Perspective.

 

 

What Is the Purpose of This Chapter?
Why Is Software Architecture Important?
What Should the Architecture Be Based on, the Problem Being Solved or the Problem Domain?
Should the Software Architecture Be Based on the Policy of the Problem?
Do Customers Ever Change Their Requirements?
Are Stable Requirements Desirable?
What Is the Key to Planning for Change?
What Is a Framework?
What Is the “Inversion of Control” Exhibited by Frameworks?
What Is an Extensible, Domain-Specific Framework?
What Characteristics Make a Framework Extensible Yet Domain-Specific?
What Happens if the Domain Analysis Is Incorrect?
How Much Effort Should Be Expended to Support Change — That Is, How Much Is Extensibility Worth?
How Does an Architect Make the Software Architecture Flexible?
What Is the Secret to Achieving Reuse?
 

II. OBJECT-ORIENTED DESIGN.

 

 


5. Object-Oriented Fundamentals.

 

 

What Is the Purpose of This Chapter?
Why Is the World Adopting OO Technology?
What Are Some of the Benefits of Using C++ for OO Programming?
What Are the Fundamental Concepts of Object-Oriented Technology?
Why Are Classes Important?
What Is an Object?
What Are the Desirable Qualities of an Object?
How Are Classes Better Than the Three Basic Building Blocks of Procedural Software?
What Is the Purpose of Composition?
What Is the Purpose of Inheritance?
What Are the Advantages of Polymorphism and Dynamic Binding?
How Does OO Help Produce Flexible and Extensible Software?
How Can Old Code Call New Code?
What Is an Abstraction and Why Is It Important?
Should Abstractions Be User-Centric or Developer-Centric?
What's the Difference between Encapsulation and Abstraction?
What Are the Consequences of Encapsulating a Bad Abstraction?
What's the Value of Separating Interface from Implementation?
How Can Separating Interface from Implementation Improve Performance as Well as Flexibility?
What Is the Best Way to Create a Good Interface to an Abstraction?
How Are Get/Set Member Functions Related to Poorly Designed Interfaces?
Should There Be a Get and a Set Member Function for Each Member Datum?
Is the Real Purpose of a Class to Export Data?
Should OO Be Viewed as Data-Centric?


6. Specification of Observable Behavior.

 

 

What Is the Purpose of This Chapter?
Should Users of a Member Function Rely on What the Code Actually Does or on the Specification?
What Are the Advantages of Relying on the Specification Rather Than the Implementation?
What Are Advertised Requirements and Advertised Promises?
How Are the Advertised Requirements and Advertised Promises of the Member Functions Specified?
Why Are Changes Feared in Development Organizations That Don't Use Specification?
How Do Developers Determine if a Proposed Change Will Break Existing Code?
What Are the Properties of a Substitutable (Backward Compatible) Change in a Specification?
How Can It Be Shown That the Implementation of a Member Function Fulfills Its Specification?
Is It Possible to Keep the Specification Synchronized with the Code?


7. Proper Inheritance.

 

 

What Is Proper Inheritance?
What Are the Benefits of Proper Inheritance?
What Is Improper Inheritance?
Isn't the Difference between Proper and Improper Inheritance Obvious?
Is Substitutability Based on What the Code Does or What the Specification Promises the Code Will Do?
Is It Proper to Revoke (Hide) an Inherited Public: Member Function?
What Is Specialization?
What Do Subsets Have to Do with Proper Inheritance?


8. Detecting and Correcting Improper Inheritance.

 

 

Can Improper Inheritance Wreck a Project?
What's the Best Way to Learn How to Avoid Improper Inheritance?
Is Intuition a Reliable Guide to Understanding Proper Inheritance?
Is an Ostrich a Kind-Of Bird?
Should an Overridden Virtual Function Throw an Exception?
Can an Overridden Virtual Function Be a No-Op?
Why Does C++ Make It So Hard to Fix the Ostrich/Bird Dilemma?
Should Circle Inherit from Ellipse?
What Can Be Done about the Asymmetric-Circle Dilemma?
What Is the One Issue in These FAQs That Doesn't Seem to Die?
Should Stack Inherit from List?
Is Code Reuse the Main Purpose of Inheritance?
Is Container-of-Thing a Kind-Of Container-of-Anything?
Is Bag-of-Apple a Kind-Of Bag-of-Fruit, Assuming Bag-of-Fruit Allows the Insertion of Any Kind-Of Fruit?
Is Parking-Lot-for-Cars a Kind-Of Parking-Lot-for-Arbitrary-Vehicles (Assuming Parking-Lot-for-Vehicles Allows Parking Any Kind-Of Vehicle)?
Is Array-Of Derived a Kind-Of Array-Of Base?
Does the Fact That an Array-Of Derived Can Be Passed as an Array-Of Base Mean That Arrays Are Bad?


9. Error Handling Strategies.

 

 

Is Error Handling a Major Source of Fundamental Mistakes?
How Should Runtime Errors Be Handled in C++?
What Happens to Objects in Stack Frames That Become Unwound During the Throw / Catch Process?
What Is an Exception Specification?
What Are the Disadvantages of Using Return Codes for Error Handling?
What Are the Advantages of Throw...Catch?
Why Is It Helpful to Separate Normal Logic from Exception Handling Logic?
What Is the Hardest Part of Using Exception Handling?
When Should a Function Throw an Exception?
What Is the Best Approach for the Hierarchy of Exception Objects?
How Should Exception Classes Be Named?
Where Do Setjmp and Longjmp Belong in C++?


10. Testing Strategies.

 

 

What Is the Purpose of This Chapter?
What Are the Advantages of Self-Testing Objects?
What Are Some Common Excuses People Use for Not Building Self-Testing Into Their Objects?
What Will Happen if Techniques Like Those Presented Here Are Not Used?
When Is a Class Correct?
What Is Behavioral Self-Testing?
What Is a Class Invariant?
Why Should the Invariant Be Captured Explicitly?
When Should the Testinvariant() Member Function Be Called?
What Can Be Done to Ensure That an Object Doesn't Get Blown Away by a Wild Pointer?
 

III. LANGUAGE FACILITIES.

 

 


11. References.

 

 

What Is a Reference?
What Does “Referent” Mean?
When Can a Reference Be Attached to Its Referent?
What Happens When a Value Is Assigned to a Reference?
What Is a Local Reference?
What Does It Mean to Return a Reference?
What Is the Result of Taking the Address of a Reference?
Can a Reference Be Made to Refer to a Different Referent?
Why Use References When Pointers Can Do Everything References Can Do?
Aren't References Just Pointers in Disguise?
When Are Pointers Needed?
Why Do Some People Hate References?
Does Int& Const X Make Sense?


12. New and Delete.

 

 

Does New Do More Than Allocate Memory?
Why Is New Better Than Good Old Trustworthy Malloc()?
Does C++ Have a Counterpart to Realloc() That Goes Along with New and Delete?
Can Pointers Returned from New Be Deallocated with Free()? Can Pointers Returned from Malloc() Be Deallocated with Delete?
Does Delete P Delete the Pointer P or the Referent *P?
Should the Pointer Returned from New Fred() Be Checked to See if It Is NULL?
How Can New Be Convinced to Return NULL Rather Than Throw an Exception?
How Can New Be Set Up to Automatically Flush Pools of Recycled Objects Whenever Memory Runs Low?
What Happens if Delete P Is Called When P Is NULL?
What Happens When a Pointer Is Deleted Twice?
How Can an Array of Things Be Allocated and Deallocated?
What if Delete P (Not Delete P) Is Used to Delete an Array Allocated Via New FredN?
Can the of Delete P Be Dropped When P Points to an Array of Some Built-in Type Such as Char?
How Is an Object Constructed at a Predetermined Position in Memory?
How Can Class Fred Guarantee That Fred Objects Are Created Only with New and Not on the Stack?
How Are Objects Created by Placement New Destroyed?
in P = New Fred(), Does the Fred Memory “Leak” if the Fred Constructor Throws an Exception?
Is It Legal (and Moral) for a Member Function to Say Delete This?
After P = New FredN, How Does the Compiler Know That There Are N Objects to Be Destructed During Delete P?


13. Inline Functions.

 

 

What Is the Purpose of Inline Functions?
What Is the Connection between the Keyword “Inline” and “Inlined” Functions?
Are There Any Special Rules about Inlining?
What Is the One-Definition Rule (ODR)?
What Are Some Performance Considerations with Inline Functions?
Do Inlined Functions Improve Performance?
Do Inlined Functions Increase the Size of the Executable Code?
Why Shouldn't the Inlining Decision Be Made When the Code Is First Written?
What Happens When a Programmer Uses an Inlined Function Obtained from a Third Party?
Is There an Easy Way to Swap between Inline and Non-Inline Code?


14. Const Correctness.

 

 

How Should Pointer Declarations Be Read?
How Can C++ Programmers Avoid Making Unexpected Changes to Objects?
Does Const Imply Runtime Overhead?
Does Const Allow the Compiler to Generate More Efficient Code?
Is Const Correctness Tedious?
Why Should Const Correctness Be Done Sooner Rather Than Later?
What's the Difference between an Inspector and a Mutator?
When Should a Member Function Be Declared as Const?
Does Const Apply to the Object's Bitwise State or Its Abstract State?
When Should Const Not Be Used in Declaring Formal Parameters?
When Should Const Not Be Used in Declaring a Function Return Type?
How Can a “Nonobservable” Data Member Be Updated within a Const Member Function?
Can an Object Legally Be Changed Even Though There Is a Const Reference (Pointer) to It?
Does Const_Cast Mean Lost Optimization Opportunities?


15. Namespaces.

 

 

What Is the Purpose of This Chapter?
What Is a Namespace?
How Can Code Outside a Namespace Use Names Declared within That Namespace?
What Happens if Two Namespaces Contain the Same Name?
What Are Some of the Rules for Using Namespaces?
What Is Name Lookup?
What Are the Tradeoffs between the Various Techniques for Using Names from a Namespace, Particularly the Standard Namespace?
Can Namespaces Break Code?
Do Namespaces Have Any Other Applications?
How Do Namespaces Solve the Problem of Long Identifiers?


16. Using Static.

 

 

What Is the Purpose of This Chapter?
What Are Static Class Members?
What Is an Analogy for Static Data Members?
Can Inline Functions Safely Access Static Data Members?
What Is an Analogy for Static Member Functions?
How Is a Static Data Member Similar to a Global Variable?
How Is a Static Member Function Similar to a Friend Function?
What Is the Named Constructor Idiom?
How Should Static Member Functions Be Called?
Why Might a Class with Static Data Members Get Linker Errors?
How Is a Const Static Data Member Initialized?
What Is the Right Strategy for Implementing a Function That Needs to Maintain State between Calls?
How Can the Function Call Operator Help with Functionoids?
Is It Safe to Be Ignorant of the Static Initialization Order Problem?
What Is a Simple and Robust Solution to the Static Initialization Order Problem?
What if the Static Object's Destructor Has Important Side Effects That Must Eventually Occur?
What if the Static Object's Destructor Has Important Side Effects That Must Eventually Occur and the Static Object Must Be Accessed by Another Static Object's Destructor?
What Are Some Criteria for Choosing between All These Various Techniques?


17. Derived Classes.

 

 

What Is the Purpose of This Chapter?
How Does C++ Express Inheritance?
What Is a Concrete Derived Class?
Why Can't a Derived Class Access the Private: Members of Its Base Class?
How Can a Base Class Protect Derived Classes So That Changes to the Base Class Will Not Affect Them?
Can a Derived Class Pointer Be Converted Into a Pointer to Its Public Base Class?
How Can a Class Y Be a Kind-Of Another Class X as Well as Getting the Bits of X?
How Can a Class Y Get the Bits of an Existing Class X Without Making Y a Kind-Of X?
How Can a Class Y Be a Kind-Of Another Class X Without Inheriting the Bits of X?


18. Access Control.

 

 

What Is the Purpose of This Chapter?
How Are Private:, Protected:, and Public: Different?
Why Can't Subclasses Access the Private: Parts of Their Base Class?
What's the Difference between the Keywords Struct and Class?
When Should a Data Member Be Protected: Rather Than Private:?
Why Is Private: the Default Access Level for a Class?


19. Friend Classes and Friend Functions.

 

 

What Is a Friend?
What's a Good Mental Model for Friend Classes?
What Are Some Advantages of Using Friend Classes?
Do Friends Violate the Encapsulation Barrier?
What Is a Friend Function?
When Should a Function Be Implemented as a Friend Function Rather Than a Member Function?
What Are Some Guidelines to Make Sure Friend Functions Are Used Properly?
What Does It Mean That Friendship Isn't Transitive?
What Does It Mean That Friendship Isn't Inherited?
What Does It Mean That Friends Aren't Virtual?
What Qualities Suggest a Friend Function Rather Than a Member Function?
Should Friend Functions Be Declared in the Private:, Protected:, or Public: Section of a Class?
What Is a Private Class?
How Are Objects of a Class Printed?
How Do Objects of a Class Receive Stream Input?


20. Constructors and Destructors.

 

 

What Is the Purpose of a Constructor?
What Is C++'S Constructor Discipline?
What Is the Purpose of a Destructor?
What Is C++'S Destructor Discipline?
What Happens When a Destructor Is Executed?
What Is the Purpose of a Copy Constructor?
When Is a Copy Constructor Invoked?
What Is the “Default Constructor?”
Should One Constructor Call Another Constructor as a Primitive?
Does the Destructor for a Derived Class Need to Explicitly Call the Destructor of Its Base Class?
How Can a Local Object Be Destructed Before the End of Its Function?
What Is a Good Way to Provide Intuitive, Multiple Constructors for a Class?
When the Constructor of a Base Class Calls a Virtual Function, Why Isn't the Override Called?
When a Base Class Destructor Calls a Virtual Function, Why Isn't the Override Called?
What Is the Purpose of Placement New?


21. Virtual Functions.

 

 

What Is the Purpose of This Chapter?
What Is a Virtual Member Function?
How Much Does It Cost to Call a Virtual Function Compared to Calling a Normal Function?
How Does C++ Perform Static Typing While Supporting Dynamic Binding?
Can Destructors Be Virtual?
What Is the Purpose of a Virtual Destructor?
What Is a Virtual Constructor?
What Syntax Should Be Used When a Constructor or Destructor Calls a Virtual Function in Its Object?
Should the Scope Operator :: Be Used When Invoking Virtual Member Functions?
What Is a Pure Virtual Member Function?
Can a Pure Virtual Function Be Defined in the Same Class That Declares It?
How Should a Virtual Destructor Be Defined When It Has No Code?
Can an ABC Have a Pure Virtual Destructor?
How Can the Compiler Be Kept from Generating Duplicate Out-Lined Copies of Inline Virtual Functions?
Should a Class with Virtual Functions Have at Least One Non-Inline Virtual Function?


22. Initialization Lists.

 

 

What Are Constructor Initialization Lists?
What Will Happen if Constructor Initialization Lists Are Not Used?
What's the Guideline for Using Initialization Lists in Constructor Definitions?
Is It Normal for Constructors to Have Nothing Inside Their Body?
How Is a Const Data Member Initialized?
How Is a Reference Data Member Initialized?
Are Initializers Executed in the Same Order in Which They Appear in the Initialization List?
How Should Initializers Be Ordered in a Constructor's Initialization List?
Is It Moral for One Member Object to Be Initialized Using Another Member Object in the Constructor's Initialization List?
What if One Member Object Has to Be Initialized Using Another Member Object?
Are There Exceptions to the Rule “Initialize All Member Objects in an Initialization List?”
How Can an Array of Objects Be Initialized with Specific Initializers?


23. Operator Overloading.

 

 

Are Overloaded Operators Like Normal Functions?
When Should Operator Overloading Be Used?
What Operators Can't Be Overloaded?
Is the Goal of Operator Overloading to Make the Class Easier to Understand?
Why Do Subscript Operators Usually Come in Pairs?
What Is the Most Important Consideration for Operators Such as +=, +, and =?
How Are the Prefix and Postfix Versions of Operator++ Distinguished?
What Should the Prefix and Postfix Versions of Operator++ Return?
How Can a Matrix-Like Class Have a Subscript Operator That Takes More Than One Subscript?
Can a ** Operator Serve as an Exponentiation Operator?


24. Assignment Operators.

 

 

What Should Assignment Operators Return?
What Is Wrong with an Object Being Assigned to Itself?
What Should Be Done about Self-Assignment?
Should an Assignment Operator Throw an Exception After Partially Assigning an Object?
How Should the Assignment Operator Be Declared in an ABC?
When Should a User-Defined Assignment Operator Mimic the Assignment Operator That the Compiler Would Generate Automatically?
What Should Be Returned by Private: and Protected: Assignment Operators?
Are There Techniques That Increase the Likelihood That the Compiler-Synthesized Assignment Operator Will Be Right?
How Should the Assignment Operator in a Derived Class Behave?
Can an ABC's Assignment Operator Be Virtual?
What Should a Derived Class Do a Base Class's Assignment Operator Is Virtual?
Should the Assignment Operator Be Implemented by Using Placement New and the Copy Constructor?


25. Templates.

 

 

What Is the Purpose of Templates?
What Are the Syntax and Semantics for a Class Template?
How Can a Template Class Be Specialized to Handle Special Cases?
What Are the Syntax and Semantics for a Function Template?
Should a Template Use Memcpy() to Copy Objects of Its Template Argument?
Why Does the Compiler Complain about >≫ When One Template Is Used Inside Another?


26. Exception Tactics.

 

 

What Belongs in a Try Block?
When Should a Function Catch an Exception?
Should a Catch Block Fully Recover from an Error?
How Should a Constructor Handle a Failure?
What Are Zombie Objects (and Why Should They Be Avoided)?
What Should an Object Do if One of Its Member Objects Could Throw an Exception During Its Constructor?
Should Destructors Throw Exceptions When They Fail?
Should Destructors Call Routines That May Throw Exceptions?
Should Resource Deallocation Primitives Signal Failure by Throwing an Exception?
What Should the Terminate() Function Do?
What Should the Unexpected() Function Do?
Under What Circumstances Can an Overridden Virtual Member Function Throw Exceptions Other Than Those Listed by the Specification of the Member Function in the Base Class?
How Might the Exception-Handling Mechanism Cause a Program to Silently Crash?


27. Types and RTTI.

 

 

What Is the Purpose of This Chapter?
What Is Static Type Checking?
What Is Dynamic Type Checking?
What Is the Basic Problem with Dynamic Type Checking?
How Can Dynamic Type Checking Be Avoided?
Are There Better Alternatives to Dynamic Type Checking?
What Is a Capability Query?
What Is an Alternative to Dynamic Type Checking with Containers?
Are There Cases Where Dynamic Type Checking Is Necessary?
Given a Pointer to an ABC, How Can the Class of the Referent Be Found?
What Is a Downcast?
What Is an Alternative to Using Downcasts?
Why Are Downcasts Dangerous?
Should the Inheritance Graph of C++ Hierarchies Be Tall or Short?
Should the Inheritance Graph of C++ Hierarchies Be Monolithic or a Forest?
What Is Runtime Type Identification (RTTI)?
What Is the Purpose of Dynamic_Cast≪T≫()?
Is Dynamic_Cast≪T≫() a Panacea?
What Does Static_Cast≪T≫() Do?
What Does Typeid() Do?
Are There Any Hidden Costs for Type-Safe Downcasts?


28. Containers.

 

 

What Are Container Classes and What Are the Most Common Mistakes Made with Container Classes?
Are Arrays Good or Evil?
Should Application Development Organizations Create Their Own Container Classes?
What Are Some Common Mistakes with Containers of Pointers?
Does This Mean That Containers of Pointers Should Be Avoided?
Surely Good Old-Fashioned Char* Is an Exception, Right?
Can Auto_Ptr≪T≫ Simplify Ownership Problems with Containers of Pointers?
Can a Java-Like Object Class Simplify Containers in C++?
What's the Difference between a Homogeneous and a Heterogeneous Container?
Is It a Good Idea to Use a “Best of Breed” Approach When Selecting Container Classes?
Should All Projects Use C++'S Standardized Containers?
What Are the C++ Standardized Container Classes?
What Are the Best Applications for the Standardized C++ Sequence Container Classes?
What Are the Best Situations for the Standardized C++ Associative Container Classes?
 

IV. TOPICS.

 

 


29. Mixing Overloading with Inheritance.

 

 

What Is the Difference between Overloaded Functions and Overridden Functions?
What Is the Hiding Rule?
How Should the Hiding Rule Be Handled?
What Should a Derived Class Do When It Redefines Some but Not All of a Set of Overloaded Member Functions Inherited from the Base Class?
Can Virtual Functions Be Overloaded?


30. The Big Three.

 

 

What Is the Purpose of This Chapter?
What Are the Big Three?
What Happens When an Object Is Destroyed That Doesn't Have an Explicit Destructor?
What Happens if an Object Is Copied but Doesn't Have an Explicit Copy Constructor?
What Happens When an Object That Doesn't Have an Explicit Assignment Operator Is Assigned?
What Is the Law of the Big Three?
Which of the Big Three Usually Shows Up First?
What Is Remote Ownership?
How Is Remote Ownership Special?
What if a Class Owns a Referent and Doesn't Have All of the Big Three?
Are There Any C++ Classes That Help Manage Remote Ownership?
Does Auto_Ptr Enforce the Law of the Big Three and Solve the Problems Associated with Remote Ownership?
Are There Cases Where One or Two of the Big Three May Be Needed but Not All Three?
Are There Any Other Circumstances That Might Explicitly Warrant the Big Three?
Why Does Copying an Object Using Memcpy() Cause a Program Crash?
Why Do Programs with Variable-Length Argument Lists Crash?
Why Do Programs That Use Realloc() to Reallocate an Array of Objects Crash?


31. Using Objects to Prevent Memory Leaks.

 

 

When Are Memory Leaks Important?
What Is the Easiest Way to Avoid Memory Leaks?
What Are the Most Important Principles for Resource Management?
Should the Object That Manages a Resource Also Perform Operations That May Throw Exceptions?
Should an Object Manage Two or More Resources?
What if an Object Has a Pointer to an Allocation and One of the Object's Member Functions Deletes the Allocation?
How Should a Pointer Variable Be Handled After Being Passed to Delete?
What Should Be Done with a Pointer to an Object That Is Allocated and Deallocated in the Same Scope?
How Easy Is It to Implement Reference Counting with Pointer Semantics?
Is Reference Counting with Copy-on-Write Semantics Hard to Implement?
How Can Reference Counting Be Implemented with Copy-on-Write Semantics for a Hierarchy of Classes?


32. Wild Pointers and Other Devilish Errors.

 

 

What Is a Wild Pointer?
What Happens to a Program That Has Even One Wild Pointer?
What Does the Compiler Mean by the Warning “Returning a Reference to a Local Object?”
How Should Pointers Across Block Boundaries Be Controlled?
Is the Reference-Versus-Pointer Issue Influenced by Whether or Not the Object Is Allocated from the Heap?
When Should C-Style Pointer Casts Be Used?
Is It Safe to Bind a Reference Variable to a Temporary Object?
Should a Parameter Passed by Const Reference Be Returned by Const Reference?
Should Template Functions for Things Like Min(X,Y) or Abs(X) Return a Const Reference?
When Is Zero Not Necessarily Zero?


33. High-Performance Software.

 

 

Is Bad Performance a Result of Bad Design or Bad Coding?
What Are Some Techniques for Improving Performance?
What Is an Advantage of Using Pointers and References?
What Is a Disadvantage of Lots of References and Pointers?
How Else Can Member Objects Improve Performance Over Pointers?
Which Is Better, ++I or I++?
What Is the Performance Difference between Fred X(5); and Fred Y = 5; and Fred Z = Fred(5);?
What Kinds of Applications Should Consider Using Final Classes and Final Member Functions?
What Is a Final Class?
What Is a Final Member Function?
How Can Final Classes and Final Member Functions Improve Performance?
When Should a Nonfinal Virtual Function Be Invoked with a Fully Qualified Name?
Should Full Qualification Be Used When Calling Another Member Function of the Same Class?
Do Final Classes and Final Member Functions Cause a Lot of Code Duplication?
Why Do Some Developers Dislike Final Member Functions and Final Classes?
Can a Programming Language — Rather Than Just the Compiler — Affect the Performance of Software?


34. COM and Active X.

 

 

Who Should Read This Chapter?
What Is the Component Object Model?
What Are Activex and OLE?
What Does the Name Component Object Model Mean?
What Is a “Binary Object Model?”
What Are the Key Features of COM?
What Are Guids?
Why Does COM Need Guids (and Clsids and Iids)?
What Is an Interface?
What Is the Iunknown Interface?
How Many Ways Are There to Specify COM Interfaces?
What Are COM Classes and COM Objects?
How Hard Is It for Callers to Create and Use a COM Object?
How Does COM Provide Language Transparency?
How Does COM Provide Location Transparency?
What Types of Errors Occur Due to Reference Counting?
What Mechanism Does COM Define for Error Handling?
How Are Interfaces Versioned?
Is COM Object Oriented?
What Is the Biggest Problem with COM?
What Are the Major Differences between COM and C++?
When Should a Class Be Defined as a COM Class?
What Is Automation?
What Are Dispatch Interfaces?
When Should a Class Expose a Dispatch Interface?
How Does Automation Work?
How Does Invoke Accomplish All of This?
What Is a Type Library?
What Are the Benefits of Using Type Libraries?
How Do Type Libraries Improve Performance?
What Are Dual Interfaces?
What Limitations Are There on Dual Interfaces?
What Are OLE Custom Controls and Activex Controls?
Why Do Activex Controls Differ from OLE Custom Controls?
What Is a Control Container?
What Are Component Categories?
What Are Events?
What Is DCOM?
How Stable Is DCOM's Infrastructure?
What Is COM+?


35. Transitioning to CORBA.

 

 

What Is CORBA?
What Is an ORB?
What Is IDL?
What Is COS?
What Is OMA?
What Is OMG?
What Is the Purpose of This Chapter?
What Is the Most Important Message of This Chapter?
What Are the Important Concepts Behind CORBA?
Isn't OMG IDL Pretty Much the Same as C++?
Is the Lifecycle of a CORBA Object the Same as the Lifecycle of a C++ Object?
Is the C++ Code That Interacts with the CORBA Implementation Portable to a Different CORBA Vendor?
How Do CORBA Exceptions Compare to C++ Exceptions?
Which CORBA Implementation Is Best? Is CORBA Better Than COM?


36. C Language Considerations.

 

 

What Are the Main Issues When Mixing C and C++ Code in the Same Application?
How Can C++ Code Call C Code?
How Can C Code Call C++ Code?
Why Is the Linker Giving Errors for C Functions Called from C++ Functions and Vice Versa?
How Can an Object of a C++ Class Be Passed to or from a C Function?
Can a C Function Directly Access Data in an Object of a C++ Class?
Can C++ I/O (≪Iostream≫) Be Mixed with C I/O (≪Stdio.H≫)?
Which Is Safer: ≪Iostream≫ or ≪Stdio.H≫?
Which Is More Extensible: ≪Iostream≫ or ≪Stdio.H≫?
Which Is More Flexible: ≪Iostream≫ or ≪Stdio.H≫?
Why Does It Seem That C++ Programming Feels Farther Away from the Machine Than C?
Why Does C++ Do More Things Behind Your Back Than C Does?


37. Private and Protected Inheritance.

 

 

What Are Private Inheritance and Protected Inheritance?
What Is the Difference between Private Inheritance and Protected Inheritance?
What Is the Syntax and Semantics for Private and Protected Inheritance?
When Should Normal Has-a Be Used, Rather Than Private or Protected Inheritance?
What Are the Access Rules for Public, Protected, and Private Inheritance?
In a Private or Protected Derived Class, How Can a Member Function That Was Public in the Base Class Be Made Public in the Derived Class?
Should a Pointer Be Cast from a Private or Protected Derived Class to Its Base Class?


38. Pointers to Member Functions.

 

 

What Is the Type of a Pointer to a Nonstatic Member Function?
Can Pointers to Nonstatic Member Functions Be Passed to Signal Handlers, X Event Call-Back Handlers, and So on, That Expect C-Like Function Pointers?
What Is One of the Most Common Errors When Using Pointers to Member Functions?
How Is an Array of Pointers to Nonstatic Member Functions Declared?


39. The Transition to OO and C++.

 

 

Who Should Read This Chapter?
What Are the Key Messages of This Chapter?
How Many Stages of Technical Expertise Are There in the Transition?
Why Bother Defining Levels of Expertise?
Can OO/C++ Be Learned from a Book?
Can OO/C++ Be Learned from a Course?
What Is the Key to Learning OO/C++?
Are Small Projects a Good Way to Get Your Feet Wet?
Does Being a Good C Programmer Help When Learning OO/C++?
What Skills Help When Learning OO/C++?


Index. 0201309831T04062001


Back to Top

 

 

Reader Reviews

 

“This is no mere reprint. This is a great book — a definite gem.”

 

—Cyberdiem.com

 


Back to Top

 

 

商品描述(中文翻譯)

 

目錄

致謝.

 

 

 

 

I. 前言.

 

 

 

1. 介紹.

 

本章的目的為何?

C++ 常見問題是什麼?

本書的目標讀者是誰?

這是一本關於 C++ 的書嗎?

為什麼開發者需要 C++ 和物件導向技術的指南?

這些常見問題的答案提供了什麼樣的指導?

什麼是電子常見問題,為什麼在電子常見問題免費的情況下還要購買這本書?

如果你已經擁有第一版,為什麼還要購買這一版?

本書使用了什麼慣例?



2. 基本 C++ 語法與語義.

 

本章的目的為何?

main() 的基本概念是什麼?

函數的基本概念是什麼?

預設參數的基本概念是什麼?

局部(自動)物件的基本概念是什麼?

使用顯式參數構造物件的基本概念是什麼?

動態分配(new)物件的基本概念是什麼?

內部範疇中的局部物件的基本概念是什麼?

通過引用傳遞物件的基本概念是什麼?

通過值傳遞物件的基本概念是什麼?

通過指針傳遞物件的基本概念是什麼?

流輸出的基本概念是什麼?

流輸入的基本概念是什麼?

使用包含重載運算子的類的基本概念是什麼?

使用容器類的基本概念是什麼?

創建類標頭檔案的基本概念是什麼?

定義類的基本概念是什麼?

定義成員函數的基本概念是什麼?

向類添加構造函數的基本概念是什麼?

向類添加解構函數的基本概念是什麼?

定義包含從堆中分配的物件指針的類的基本概念是什麼?

全域物件的基本概念是什麼?

拋出和捕獲異常的基本概念是什麼?

繼承和動態綁定的基本概念是什麼?



3. 理解管理視角.

 

 

本章的目的為何?

本章(及本書)的核心信息是什麼?

為什麼是管理者負責,而不是理解技術的開發者?

一個人如何管理他不理解的事物?

在 C++ 和物件導向專案中,最常見的錯誤是什麼?

什麼是「軟體彼得原則」?

組織是否應在所有專案中使用物件導向?

物件導向是否可以被忽視,直到它消失?

哪種物件導向語言最好?

對於流程和工具的正確方法是什麼?

對於現成的類庫和框架的正確方法是什麼?



4. 架構視角.

 

 

本章的目的為何?

為什麼軟體架構重要?

架構應基於解決的問題還是問題領域?

軟體架構應基於問題的政策嗎?

客戶是否會改變他們的需求?

穩定的需求是否可取?

規劃變更的關鍵是什麼?

什麼是框架?

框架所表現的「控制反轉」是什麼?

什麼是可擴展的、特定領域的框架?

使框架可擴展但又特定領域的特徵是什麼?

如果領域分析不正確會發生什麼?

支持變更需要多少努力——也就是說,擴展性值多少?

架構師如何使軟體架構靈活?

實現重用的秘訣是什麼?

 

II. 物件導向設計.

 

 



5. 物件導向基本原則.

 

 

本章的目的為何?

為什麼世界在採用物件導向技術?

使用 C++ 進行物件導向程式設計的好處有哪些?

物件導向技術的基本概念是什麼?

類別為什麼重要?

什麼是物件?

物件的理想特質是什麼?

類別如何優於程序性軟體的三個基本構建塊?

組合的目的為何?

繼承的目的為何?

多型和動態綁定的優勢是什麼?

物件導向如何幫助產生靈活和可擴展的軟體?

舊代碼如何調用新代碼?

什麼是抽象,為什麼它重要?

抽象應該以使用者為中心還是開發者為中心?

封裝和抽象之間的區別是什麼?

封裝不良抽象的後果是什麼?

將介面與實現分開的價值是什麼?

將介面與實現分開如何改善性能和靈活性?

創建良好抽象介面的最佳方法是什麼?

Get/Set 成員函數與設計不良介面的關係是什麼?

每個成員數據是否應有一個 Get 和一個 Set 成員函數?

類別的真正目的是導出數據嗎?

物件導向是否應被視為以數據為中心?



6. 可觀察行為的規範.

 

 

本章的目的為何?

成員函數的使用者應依賴代碼實際執行的內容還是規範?

依賴規範而非實現的優勢是什麼?

什麼是廣告需求和廣告承諾?

成員函數的廣告需求和廣告承諾是如何規範的?

為什麼在不使用規範的開發組織中,變更會受到恐懼?

開發者如何判斷提議的變更是否會破壞現有代碼?

規範中可替代(向後相容)變更的特性是什麼?

如何證明成員函數的實現符合其規範?

是否有可能保持規範與代碼的同步?



7. 正確的繼承.

 

 

什麼是正確的繼承?

正確繼承的好處是什麼?

什麼是錯誤的繼承?

正確繼承和錯誤繼承之間的區別不是很明顯嗎?

可替代性是基於代碼的行為還是規範所承諾的行為?

撤銷(隱藏)繼承的公共成員函數是否合適?

什麼是專門化?

子集與正確繼承有什麼關係?



8. 偵測和修正錯誤的繼承.

 

 

錯誤的繼承會毀掉一個專案嗎?

避免錯誤繼承的最佳方法是什麼?

直覺是否是理解正確繼承的可靠指導?

鴕鳥算不算一種鳥?

重寫的虛擬函數應該拋出異常嗎?

重寫的虛擬函數可以是無操作嗎?

為什麼 C++ 使得修正鴕鳥/鳥的困境如此困難?

圓形應該繼承自橢圓形嗎?

對於不對稱圓形的困境可以做些什麼?

這些常見問題中有哪一個問題似乎永遠不會消失?

堆疊應該繼承自列表嗎?

代碼重用是繼承的主要目的嗎?

「物件的容器」算不算「任何物件的容器」?

「蘋果的袋子」算不算「水果的袋子」,假設「水果的袋子」允許插入任何種類的水果?

「汽車的停車場」算不算「任意車輛的停車場」(假設「車輛的停車場」允許停放任何種類的車輛)?

「衍生的數組」算不算「基類的數組」?

「衍生的數組」可以作為「基類的數組」傳遞,這是否意味著數組是壞的?



9. 錯誤處理策略.

 

 

錯誤處理是基本錯誤的主要來源嗎?

在 C++ 中應如何處理運行時錯誤?

在拋出/捕獲過程中,堆疊幀中的物件會發生什麼?

什麼是異常規範?

使用返回碼進行錯誤處理的缺點是什麼?

使用拋出...捕獲的優勢是什麼?

將正常邏輯與異常處理邏輯分開有什麼好處?

使用異常處理最困難的部分是什麼?

函數應在何時拋出異常?

異常物件的層次結構的最佳方法是什麼?

異常類應如何命名?

Setjmp 和 Longjmp 在 C++ 中的地位是什麼?



10. 測試策略.

 

 

本章的目的為何?

自我測試物件的優勢是什麼?

人們不將自我測試納入物件中的一些常見藉口是什麼?

如果不使用此處提出的技術會發生什麼?

類別何時是正確的?

什麼是行為自我測試?

什麼是類別不變式?

為什麼不變式應該被明確捕捉?

何時應該...