C++ Gotchas: Avoiding Common Problems in Coding and Design (Paperback)
暫譯: C++ 常見陷阱:避免編碼與設計中的常見問題 (平裝本)

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: 靜態與 extern 類型
Gotcha #23: 運算子函數查找異常
Gotcha #24: 運算子 — 微妙之處

3. 預處理器

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

4. 轉換

Gotcha #29: 通過 void * 轉換
Gotcha #30: 切片
Gotcha #31: 誤解指向常數的指標轉換
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: 虛擬基類的預設初始化
Gotcha #54: 複製建構子基類初始化
Gotcha #55: 執行時靜態初始化順序
Gotcha #56: 直接與複製初始化
Gotcha #57: 直接參數初始化
Gotcha #58: 忽視返回值優化
Gotcha #59: 在建構子中初始化靜態成員

6. 記憶體與資源管理

Gotcha #60: 無法區分標量與陣列分配
Gotcha #61: 檢查分配失敗
Gotcha #62: 替換全域的 new 和 delete
Gotcha #63: 混淆成員 new 和 delete 的範圍與啟用
Gotcha #64: 拋出字串字面量
Gotcha #65: 不當的例外機制
Gotcha #66: 濫用局部地址
Gotcha #67: 無法運用資源獲取即初始化
Gotcha #68: 不當使用 auto_ptr

7. 多型性

Gotcha #69: 類型代碼
Gotcha #70: 非虛擬基類的解構函數
Gotcha #71: 隱藏非虛擬函數
Gotcha #72: 使模板方法過於靈活
Gotcha #73: 重載虛擬函數
Gotcha #74: 帶有預設參數初始化的虛擬函數
Gotcha #75: 在建構子和解構子中呼叫虛擬函數