繼 Effective C++ 之後,Scott Meyers 於 1996 推出這本「續(xù)集」。條款變得比較少,頁(yè)數(shù)倒是多了一些,原因是這次選材比「第一集」更高階,尤其是第五章。Meyers 將此章命名為技術(shù)(Techniques),并明白告訴你,其中都是一些 patterns,例如 virtual ctors、smart pointers、reference counting、proxy classes,double dispatching┅等等。這一章的每個(gè)條款篇幅都在 15~30 頁(yè)之譜,實(shí)在讓人有「山窮水盡疑無(wú)路,柳暗花明又一村」之嘆。雖然出版年代稍嫌久遠(yuǎn),本書(shū)并沒(méi)有第二版,原因是當(dāng)其出版之時(shí)(1996),C++ Standard 已經(jīng)幾乎定案,本書(shū)即依當(dāng)時(shí)的標(biāo)準(zhǔn)草案而寫(xiě)。其間與現(xiàn)今之 C++ 標(biāo)準(zhǔn)規(guī)格幾乎相同。可能變化的幾個(gè)彈性之處,Meyers 也都有所說(shuō)明與提示。讀者可以連結(jié)作者提供的網(wǎng)址,看看上下兩集的勘誤與討論(數(shù)量之多,令人驚恐。幸好多是技術(shù)討論或文字斟酌,并沒(méi)有什麼重大誤失)。本書(shū)第一頁(yè)列有它所獲得的贊譽(yù)。對(duì)於讀者,這是一份值得叁考的資料,我試著把它們譯為中文,條列於下:Ø這是一本多方面發(fā)人深省的 C++ 書(shū)籍:不論在你偶爾用到的語(yǔ)言特性上,或是在你自以為十分熟悉的語(yǔ)言特性上。只有深刻了解 C++ 編譯器如何解釋你的碼,你才有可能以 C++ 語(yǔ)言寫(xiě)出穩(wěn)健強(qiáng)固的軟體。本書(shū)是協(xié)助你獲得此等層級(jí)之了解過(guò)程中,一份極具價(jià)值的資源。讀過(guò)本書(shū)之後,我感覺(jué)像是瀏覽了 C++ 程式大師所檢閱過(guò)的碼,并獲得許多極具價(jià)值的洞見(jiàn)。- Fred Wild, Vce President of Technology,Advantage Software echnologiesØ本書(shū)內(nèi)含大量重要的技術(shù),這些技術(shù)是撰寫(xiě)優(yōu)良 C++ 程式所不可或缺的。本書(shū)解釋如何設(shè)計(jì)和實(shí)作這些觀念,以及潛伏在其他某些替代方案中的陷阱。本書(shū)亦含晚近加入之 C++ 特性的詳細(xì)說(shuō)明。任何人如果想要好好地運(yùn)用這些新特性,最好買一本并且放在隨手可得之處,以備查閱。- Chrisopher J. Van Wyk, ProfessorMahematics and Computer Science, Drew UniversityØ這是一本具備工業(yè)強(qiáng)度的最佳書(shū)籍。對(duì)於已經(jīng)閱讀過(guò) Effetive C++ 的人,這是完美的續(xù)集。- Eric Nagler, ++ Instructor and Author,Univesity of California Santa Cruz ExtensionØMore Effective C++ 是一本無(wú)微不至而且價(jià)值不扉的書(shū)籍,是 Scott 第一本書(shū) Effective C++ 的續(xù)集。我相信每一位專業(yè)的 C++ 軟體開(kāi)發(fā)人員都應(yīng)該讀過(guò)并記憶 Effective C++ 和 More Effective C++ 兩本書(shū)內(nèi)的各種招式,以及其中重要(并且有時(shí)候不可思議)的語(yǔ)言面向。我強(qiáng)烈推薦這兩本書(shū)給軟體開(kāi)發(fā)人員、測(cè)試人員、管理人員┅,每個(gè)人都可以從 Scott 專家級(jí)的知識(shí)與卓越的表達(dá)能力中獲益。- Steve Burkett, Software Consutant
譯序(侯捷) 目錄(Contents) 致謝(Acknowledgments. 中文版略) 導(dǎo)讀(Introduction) 001 基礎(chǔ)議題(Basics) 009 條款1:仔細(xì)區(qū)別 pointers 和 references 009 Distinguish between pointers and references 條款2:最好使用 C++ 轉(zhuǎn)型操作符 012 Prefer C++-style casts 條款3:絕對(duì)不要以polymorphically(多態(tài))方式來(lái)處理數(shù)組 016 Never treat arrays polymorphically 條款4:非必要不提供 default constructor 019 Avoid gratuitous default constructors 操作符(Operators) 024 條款5:對(duì)定制的型別轉(zhuǎn)換函數(shù)保持警覺(jué) 024 Be wary of user-defined conversion functions 條款6:區(qū)別 increment/decrement 操作符的 前置(prefix)和后置(postfix)型式 031 Distinguish between prefix and postfix forms of increment and decrement operators 條款7:千萬(wàn)不要重載 &&, ||, 和 , 操作符 035 Never overload &&, ||, or , 條款8:了解各種不同意義的 new 和 delete 038 Understand the different meanings of new and delete 異常(Exceptions) 044 條款9:利用 destructors 避免泄漏資源 045 Use destructors to prevent resource leaks 條款10:在 constructors 內(nèi)阻止資源泄漏(resource leaks) 050 Prevent resource leaks in constructors 條款11:禁止異常(exceptions)流出 destructors 之外 058 Prevent exceptions from leaving destructors 條款12:了解「擲出一個(gè) exception」與「?jìng)鬟f一個(gè)參數(shù)」 或「調(diào)用一個(gè)虛函數(shù)」之間的差異 061 Understand how throwing an exception differs from passing a parameter or calling a virtual function 條款13:以 by reference 方式捕捉 exceptions 068 Catch exceptions by reference 條款14:明智運(yùn)用 exception specifications 072 Use exception specifications judiciously 條款15:了解異常處理(exception handling)的成本 078 Understand the costs of exception handling 效率(Efficiency) 081 條款16:謹(jǐn)記 80-20 法則 082 Remember the 80-20 rule 條款17:考慮使用 lazy evaluation 085 Consider using lazy evaluation 條款18:分期攤還預(yù)期的計(jì)算成本 093 Amortize the cost of expected computations 條款19:了解暫時(shí)對(duì)象的來(lái)源 098 Understand the origin of temporary objects 條款20:協(xié)助完成「返回值優(yōu)化(RVO)」 101 Facilitate the return value optimization 條款21:利用重載技術(shù)(overload)避免隱式型別轉(zhuǎn)換 105 Overload to avoid implicit type conversions 條款22:考慮以操作符復(fù)合型式(op=)取代其獨(dú)身型式(op)107 Consider using op= instead of stand-alone op 條款23:考慮使用其它程序庫(kù) 110 Consider alternative libraries 條款24:了解 virtual functions、multiple inheritance、virtual base classes、 runtime type identification 所需的成本 113 Understand the costs of virtual functions, multiple inheritance, virtual base classes, and RTTI 技術(shù)(Techniques, Idioms, Pattern) 123 條款25:將 constructor 和 non-member functions 虛化 123 Virtualizing constructors and non-member functions 條款26:限制某個(gè) class 所能產(chǎn)生的對(duì)象數(shù)量 130 Limiting the number of objects of a class 條款27:要求(或禁止)對(duì)象產(chǎn)生于 heap 之中 145 Requiring or prohibiting heap-based objects 條款28:Smart Pointers(智能指針) 159 條款29:Reference counting(引用計(jì)數(shù)) 183 條款30:Proxy classes(替身類、代理類) 213 條款31:讓函數(shù)根據(jù)一個(gè)以上的對(duì)象型別來(lái)決定如何虛化 228 Making functions virtual with respect to more than one object 雜項(xiàng)討論(Miscellany) 252 條款32:在未來(lái)時(shí)態(tài)下發(fā)展程序 252 Program in the future tense 條款33:將非尾端類(non-leaf classes)設(shè)計(jì)為 抽象類(abstract classes) 258 Make non-leaf classes abstract 條款34:如何在同一個(gè)程序中結(jié)合 C++ 和 C 270 Understand how to combine C++ and C in the same program 條款35:讓自己習(xí)慣于標(biāo)準(zhǔn) C++ 語(yǔ)言 277 Familiarize yourself with the language standard 推薦書(shū)目 285 auto_ptr 實(shí)現(xiàn)代碼 291 索引1(General Index) 295 索引2(Index of Example Classes, Functions, and Templtes) 313