讀這本書其實還是花了一點時間的,其中的一些條款的内涵及外延非常豐富。我覺得這是很用心去看的一本書,但在看書過程中,還是出現了浮躁的現象。實際上留給我看書的時間是有點不足,是以又想快些看完。事情總是兩難的。 我接下來買了《Effective C++》的第三版,我想這可能是我認真讀的最後一本C++讀物了,再往後要涉獵的C++的書籍已經不多,充其量是把《C++程式設計思想》的第二卷看完,我還剩下後面幾章了。 希望以後經常能夠有條件看書,有條件寫讀書筆記。 目錄
基礎議題(Basics)
條款1:仔細差別 pointers 和 references
Distinguish between pointers and references
條款2:最好使用 C++ 轉型操作符
Prefer C++-style casts
條款3:絕對不要以polymorphically(多态)方式來處理數組
Never treat arrays polymorphically
條款4:非必要不提供 default constructor
Avoid gratuitous default constructors
操作符(Operators)
條款5:對定制的型别轉換函數保持警覺
Be wary of user-defined conversion functions
條款6:差別 increment/decrement 操作符的
前置(prefix)和後置(postfix)型式
Distinguish between prefix and postfix forms of increment
and decrement operators
條款7:千萬不要重載 &&, ||, 和 , 操作符
Never overload &&, ||, or ,
條款8:了解各種不同意義的 new 和 delete
Understand the different meanings of new and delete
異常(Exceptions)
條款9:利用 destructors 避免洩漏資源
Use destructors to prevent resource leaks
條款10:在 constructors 内阻止資源洩漏(resource leaks)
Prevent resource leaks in constructors
條款11:禁止異常(exceptions)流出 destructors 之外
Prevent exceptions from leaving destructors
條款12:了解「擲出一個 exception」與「傳遞一個參數」
或「調用一個虛函數」之間的差異
Understand how throwing an exception differs from
passing a parameter or calling a virtual function
條款13:以 by reference 方式捕捉 exceptions
Catch exceptions by reference
條款14:明智運用 exception specifications
Use exception specifications judiciously
條款15:了解異常處理(exception handling)的成本
Understand the costs of exception handling
效率(Efficiency)
條款16:謹記 80-20 法則
Remember the 80-20 rule
條款17:考慮使用 lazy evaluation
Consider using lazy evaluation
條款18:分期攤還預期的計算成本
Amortize the cost of expected computations
條款19:了解暫時對象的來源
Understand the origin of temporary objects
條款20:協助完成「傳回值優化(RVO)」
Facilitate the return value optimization
條款21:利用重載技術(overload)避免隐式型别轉換
Overload to avoid implicit type conversions
條款22:考慮以操作符複合型式(op=)取代其獨身型式(op)
Consider using op= instead of stand-alone op
條款23:考慮使用其它程式庫
Consider alternative libraries
條款24:了解 virtual functions、multiple inheritance、virtual base classes、
runtime type identification 所需的成本
Understand the costs of virtual functions, multiple inheritance,
virtual base classes, and RTTI
技術(Techniques, Idioms, Pattern)
條款25:将 constructor 和 non-member functions 虛化
Virtualizing constructors and non-member functions
條款26:限制某個 class 所能産生的對象數量
Limiting the number of objects of a class
條款27:要求(或禁止)對象産生于 heap 之中
Requiring or prohibiting heap-based objects
條款28:Smart Pointers(智能指針)
條款29:Reference counting(引用計數)
條款30:Proxy classes(替身類、代理類)
條款31:讓函數根據一個以上的對象型别來決定如何虛化
Making functions virtual with respect to more than one object
雜項讨論(Miscellany)
條款32:在未來時态下發展程式
Program in the future tense
條款33:将非尾端類(non-leaf classes)設計為
抽象類(abstract classes)
Make non-leaf classes abstract
條款34:如何在同一個程式中結合 C++ 和 C
Understand how to combine C++ and C in the same program
條款35:讓自己習慣于标準 C++ 語言
Familiarize yourself with the language standard