C++ Gotchas: Avoiding Common Problems in Coding and Design (Paperback)

Stephen C. Dewhurst

  • 出版商: Addison Wesley
  • 出版日期: 2002-11-26
  • 定價: $1,925
  • 售價: 9.0$1,733
  • 語言: 英文
  • 頁數: 352
  • 裝訂: Paperback
  • ISBN: 0321125185
  • ISBN-13: 9780321125187
  • 相關分類: C++ 程式語言
  • 立即出貨

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

商品描述

C++ Gotchas is a guide to avoiding and correcting ninety-nine of the most common, destructive, and interesting C++ design and programming errors. Students will get a look inside look at the more subtle C++ features and programming techniques.

This book discusses basic errors present in almost all C++ code, as well as complex mistakes in syntax, preprocessing, conversions, initialization, memory and resource management, polymorphism, class design, and hierarchy design. Each error and its repercussions are explained in context, and the resolution of each problem is detailed and demonstrated.

Author Stephen Dewhurst supplies students with idioms and design patterns that can be used to generate customized solutions for common problems. students will also learn more about commonly misunderstood features of C++ used in advanced programming and design. A companion Web site, located at http://www.semantics.org, includes detailed code samples from the book.

Table of Contents

Preface.
Acknowledgments.
1. Basics.

Gotcha #1: Excessive Commenting.
Gotcha #2: Magic Numbers.
Gotcha #3: Global Variables.
Gotcha #4: Failure to Distinguish Overloading from Default Initialization.
Gotcha #5: Misunderstanding References.
Gotcha #6: Misunderstanding Const.
Gotcha #7: Ignorance of Base Language Subtleties.
Gotcha #8: Failure to Distinguish Access and Visibility.
Gotcha #9: Using Bad Language.
Gotcha #10: Ignorance of Idiom.
Gotcha #11: Unnecessary Cleverness.
Gotcha #12: Adolescent Behavior.


2. Syntax.

Gotcha #13: Array/Initializer Confusion.
Gotcha #14: Evaluation Order Indecision.
Gotcha #15: Precedence Problems.
Gotcha #16: for Statement Debacle.
Gotcha #17: Maximal Munch Problems.
Gotcha #18: Creative Declaration-Specifier Ordering.
Gotcha #19: Function/Object Ambiguity.
Gotcha #20: Migrating Type-Qualifiers.
Gotcha #21: Self Initialization.
Gotcha #22: Static and Extern Types.
Gotcha #23: Operator Function Lookup Anomaly.
Gotcha #24: Operator — Subtleties.


3. The Preprocessor.

Gotcha #25: #define Literals.
Gotcha #26: #define Pseudofunctions.
Gotcha #27: Overuse of #if.
Gotcha #28: Side Effects in Assertions.


4. Conversions.

Gotcha #29: Converting Through void *.
Gotcha #30: Slicing.
Gotcha #31: Misunderstanding Pointer-to-Const Conversion.
Gotcha #32: Misunderstanding Pointer-to-Pointer-to-Const Conversion.
Gotcha #33: Misunderstanding Pointer-to-Pointer-to-Base Conversion.
Gotcha #34: Pointer-to-MultiDimensional Array Problems.
Gotcha #35: Unchecked Downcasting.
Gotcha #36: Misusing Conversion Operators.
Gotcha #37: Unintended Constructor Conversion.
Gotcha #38: Casting Under Multiple Inheritance.
Gotcha #39: Casting Incomplete Types.
Gotcha #40: Old-Style Casts.
Gotcha #41: Static Casts.
Gotcha #42: Temporary Initialization of Formal Arguments.
Gotcha #43: Temporary Lifetime.
Gotcha #44: References and Temporaries.
Gotcha #45: Ambiguity Failure of dynamic_cast.
Gotcha #46: Misunderstanding Contravariance.


5. Initialization.

Gotcha #47: Assignment/Initialization Confusion.
Gotcha #48: Improperly Scoped Variables.
Gotcha #49: Failure to Appreciate C++'s Fixation on Copy Operations.
Gotcha #50: Bitwise Copy of Class Objects.
Gotcha #51: Confusing Initialization and Assignment in Constructors.
Gotcha #52: Inconsistent Ordering of the Member Initialization List.
Gotcha #53: Virtual Base Default Initialization.
Gotcha #54: Copy Constructor Base Initialization.
Gotcha #55: Runtime Static Initialization Order.
Gotcha #56: Direct versus Copy Initialization.
Gotcha #57: Direct Argument Initialization.
Gotcha #58: Ignorance of the Return Value Optimizations.
Gotcha #59: Initializing a Static Member in a Constructor.


6. Memory and Resource Management.

Gotcha #60: Failure to Distinguish Scalar and Array Allocation.
Gotcha #61: Checking for Allocation Failure.
Gotcha #62: Replacing Global New and Delete.
Gotcha #63: Confusing Scope and Activation of Member new and delete.
Gotcha #64: Throwing String Literals.
Gotcha #65: Improper Exception Mechanics.
Gotcha #66: Abusing Local Addresses.
Gotcha #67: Failure to Employ Resource Acquisition Is Initialization.
Gotcha #68: Improper Use of auto_ptr.


7. Polymorphism.

Gotcha #69: Type Codes.
Gotcha #70: Nonvirtual Base Class Destructor.
Gotcha #71: Hiding Nonvirtual Functions.
Gotcha #72: Making Template Methods Too Flexible.
Gotcha #73: Overloading Virtual Functions.
Gotcha #74: Virtual Functions with Default Argument Initializers.
Gotcha #75: Calling Virtual Functions in Constructors and Destructors.
Gotcha #76: Vir

商品描述(中文翻譯)

《C++ Gotchas》是一本指南,旨在避免和修正最常見、最具破壞性和有趣的C++設計和編程錯誤。學生將深入了解C++的更微妙的特性和編程技巧。

本書討論了幾乎所有C++代碼中存在的基本錯誤,以及語法、預處理、轉換、初始化、內存和資源管理、多態性、類設計和層次結構設計中的複雜錯誤。每個錯誤及其後果都在上下文中解釋,並詳細演示了每個問題的解決方法。

作者Stephen Dewhurst為學生提供了可用於生成常見問題的定制解決方案的慣用語和設計模式。學生還將更多地了解C++中常被誤解的高級編程和設計特性。附帶的網站http://www.semantics.org提供了書中詳細的代碼示例。

目錄:

前言。
致謝。
1. 基礎。

Gotcha#1:過度註釋。
Gotcha#2:魔術數字。
Gotcha#3:全局變量。
Gotcha#4:未能區分重載和默認初始化。
Gotcha#5:誤解引用。
Gotcha#6:誤解const。
Gotcha#7:對基本語言細微差別的無知。
Gotcha#8:未能區分訪問和可見性。
Gotcha#9:使用不良語言。
Gotcha#10:對成語的無知。
Gotcha#11:不必要的聰明。
Gotcha#12:青少年行為。

2. 語法。

Gotcha#13:數組/初始化程序混淆。
Gotcha#14:評估順序的猶豫。
Gotcha#15:優先級問題。
Gotcha#16:for語句的困境。
Gotcha#17:最大匹配問題。
Gotcha#18:創造性的聲明指定符排序。
Gotcha#19:函數/對象的模糊性。
Gotcha#20:遷移類型限定符。
Gotcha#21:自我初始化。
Gotcha#22:靜態和外部類型。
Gotcha#23:運算符函數查找異常。
Gotcha#24:運算符-細微差別。

3. 預處理器。

Gotcha#25:#define文字。
Gotcha#26:#define偽函數。
Gotcha#27:過度使用#if。
Gotcha#28:斷言中的副作用。

4. 轉換。

Gotcha#29:通過void *進行轉換。
Gotcha#30:切片。
Gotcha#31:誤解指向const的指針轉換。
Gotcha#32:誤解指向指針的指針轉換。
Gotcha#33:誤解指向指針的指向基類的轉換。
Gotcha#34:指向多維數組的指針問題。
Gotcha#35:未檢查的向下轉型。
Gotcha#36:誤用轉換運算符。
Gotcha#37:意外的構造函數轉換。
Gotcha#38:在多重繼承下進行轉型。
Gotcha#39:轉換不完整類型。
Gotcha#40:舊式轉型。
Gotcha#41:靜態轉型。
Gotcha#42:形式參數的臨時初始化。
Gotcha#43:臨時生命期。
Gotcha#44:引用和臨時對象。
Gotcha#45:dynamic_cast的歧義失敗。
Gotcha#46:誤解逆變。

5. 初始化。

Gotcha#47:賦值/初始化混淆。
Gotcha#48:作用域不正確的變量。
Gotcha#49:未能理解C++對拷貝操作的著迷。
Gotcha#50:類對象的位拷貝。
Gotcha#51:在構造函數中混淆初始化和賦值。
Gotcha#52:成員初始化列表的不一致順序。
Gotcha#53:虛基類的默認初始化。