> “Every C++ professional needs a copy of __Effective C++__. It is an absolute must-read for anyone thinking of doing serious C++ development. If you’ve never read __Effective C++__ and you think you know everything about C++, think again.” — **Steve Schirripa,** Software Engineer, Google > “C++ and the C++ community have grown up in the last fifteen years, and the third edition of __Effective C++__ reflects this. The clear and precise style of the book is evidence of Scott’s deep insight and distinctive ability to impart knowledge.” — **Gerhard Kreuzer,** Research and Development Engineer, Siemens AG The first two editions of __Effective C++__ were embraced by hundreds of thousands of programmers worldwide. The reason is clear: Scott Meyers’ practical approach to C++ describes the rules of thumb used by the experts — the things they almost always do or almost always avoid doing — to produce clear, correct, efficient code. The book is organized around 55 specific guidelines, each of which describes a way to write better C++. Each is backed by concrete examples. For this third edition, more than half the content is new, including added chapters on managing resources and using templates. Topics from the second edition have been extensively revised to reflect modern design considerations, including exceptions, design patterns, and multithreading. Important features of __Effective C++__ include: * Expert guidance on the design of effective classes, functions, templates, and inheritance hierarchies. * Applications of new “TR1” standard library functionality, along with comparisons to existing standard library components. * Insights into differences between C++ and other languages (e.g., Java, C#, C) that help developers from those languages assimilate “the C++ way” of doing things. Title Page......Page 6 Copyright Page......Page 7 Contents......Page 12 Praise for Effective C++, Third Edition......Page 2 Addison-Wesley Professional Computing Series......Page 5 Preface......Page 16 Acknowledgments......Page 18 Introduction......Page 22 Item 1: View C++ as a federation of languages.......Page 32 Item 2: Prefer consts, enums, and inlines to #defines.......Page 34 Item 3: Use const whenever possible.......Page 38 Item 4: Make sure that objects are initialized before they’re used.......Page 47 Item 5: Know what functions C++ silently writes and calls.......Page 55 Item 6: Explicitly disallow the use of compiler-generated functions you do not want.......Page 58 Item 7: Declare destructors virtual in polymorphic base classes.......Page 61 Item 8: Prevent exceptions from leaving destructors.......Page 65 Item 9: Never call virtual functions during construction or destruction.......Page 69 Item 10: Have assignment operators return a reference to *this.......Page 73 Item 11: Handle assignment to self in operator=.......Page 74 Item 12: Copy all parts of an object.......Page 78 Item 13: Use objects to manage resources.......Page 82 Item 14: Think carefully about copying behavior in resource-managing classes.......Page 87 Item 15: Provide access to raw resources in resource-managing classes.......Page 90 Item 16: Use the same form in corresponding uses of new and delete.......Page 94 Item 17: Store newed objects in smart pointers in standalone statements.......Page 96 Item 18: Make interfaces easy to use correctly and hard to use incorrectly.......Page 99 Item 19: Treat class design as type design.......Page 105 Item 20: Prefer pass-by-reference-to-const to pass-by-value.......Page 107 Item 21: Don’t try to return a reference when you must return an object.......Page 111 Item 22: Declare data members private.......Page 115 Item 23: Prefer non-member non-friend functions to member functions.......Page 119 Item 24: Declare non-member functions when type conversions should apply to all parameters.......Page 123 Item 25: Consider support for a non-throwing swap.......Page 127 Item 26: Postpone variable definitions as long as possible.......Page 134 Item 27: Minimize casting.......Page 137 Item 28: Avoid returning “handles” to object internals.......Page 144 Item 29: Strive for exception-safe code.......Page 148 Item 30: Understand the ins and outs of inlining.......Page 155 Item 31: Minimize compilation dependencies between files.......Page 161 Chapter 6: Inheritance and Object-Oriented Design......Page 170 Item 32: Make sure public inheritance models “is-a.”......Page 171 Item 33: Avoid hiding inherited names.......Page 177 Item 34: Differentiate between inheritance of interface and inheritance of implementation.......Page 182 Item 35: Consider alternatives to virtual functions.......Page 190 Item 36: Never redefine an inherited non-virtual function.......Page 199 Item 37: Never redefine a function’s inherited default parameter value.......Page 201 Item 38: Model “has-a” or “is-implemented-in-terms- of” through composition.......Page 205 Item 39: Use private inheritance judiciously.......Page 208 Item 40: Use multiple inheritance judiciously.......Page 213 Item 41: Understand implicit interfaces and compile-time polymorphism.......Page 220 Item 42: Understand the two meanings of typename.......Page 224 Item 43: Know how to access names in templatized base classes.......Page 228 Item 44: Factor parameter-independent code out of templates.......Page 233 Item 45: Use member function templates to accept “all compatible types.”......Page 239 Item 46: Define non-member functions inside templates when type conversions are desired.......Page 243 Item 47: Use traits classes for information about types.......Page 247 Item 48: Be aware of template metaprogramming.......Page 254 Chapter 8: Customizing new and delete......Page 260 Item 49: Understand the behavior of the new-handler.......Page 261 Item 50: Understand when it makes sense to replace new and delete.......Page 268 Item 51: Adhere to convention when writing new and delete.......Page 273 Item 52: Write placement delete if you write placement new.......Page 277 Item 53: Pay attention to compiler warnings.......Page 283 Item 54: Familiarize yourself with the standard library, including TR1.......Page 284 Item 55: Familiarize yourself with Boost.......Page 290 Appendix A: Beyond Effective C++......Page 294 Appendix B: Item Mappings Between Second and Third Editions......Page 298 B......Page 301 C......Page 302 D......Page 304 E......Page 305 F......Page 308 I......Page 309 J......Page 310 M......Page 311 O......Page 312 P......Page 313 R......Page 314 S......Page 315 T......Page 316 V......Page 317 Z......Page 318 Title Page 6 Copyright Page 7 Contents 12 Praise for Effective C++, Third Edition 2 Addison-Wesley Professional Computing Series 5 Preface 16 Acknowledgments 18 Introduction 22 Chapter 1: Accustoming Yourself to C++ 32 Item 1: View C++ as a federation of languages. 32 Item 2: Prefer consts, enums, and inlines to #defines. 34 Item 3: Use const whenever possible. 38 Item 4: Make sure that objects are initialized before they’re used. 47 Chapter 2: Constructors, Destructors, and Assignment Operators 55 Item 5: Know what functions C++ silently writes and calls. 55 Item 6: Explicitly disallow the use of compiler-generated functions you do not want. 58 Item 7: Declare destructors virtual in polymorphic base classes. 61 Item 8: Prevent exceptions from leaving destructors. 65 Item 9: Never call virtual functions during construction or destruction. 69 Item 10: Have assignment operators return a reference to *this. 73 Item 11: Handle assignment to self in operator=. 74 Item 12: Copy all parts of an object. 78 Chapter 3: Resource Management 82 Item 13: Use objects to manage resources. 82 Item 14: Think carefully about copying behavior in resource-managing classes. 87 Item 15: Provide access to raw resources in resource-managing classes. 90 Item 16: Use the same form in corresponding uses of new and delete. 94 Item 17: Store newed objects in smart pointers in standalone statements. 96 Chapter 4: Designs and Declarations 99 Item 18: Make interfaces easy to use correctly and hard to use incorrectly. 99 Item 19: Treat class design as type design. 105 Item 20: Prefer pass-by-reference-to-const to pass-by-value. 107 Item 21: Don’t try to return a reference when you must return an object. 111 Item 22: Declare data members private. 115 Item 23: Prefer non-member non-friend functions to member functions. 119 Item 24: Declare non-member functions when type conversions should apply to all parameters. 123 Item 25: Consider support for a non-throwing swap. 127 Chapter 5: Implementations 134 Item 26: Postpone variable definitions as long as possible. 134 Item 27: Minimize casting. 137 Item 28: Avoid returning “handles” to object internals. 144 Item 29: Strive for exception-safe code. 148 Item 30: Understand the ins and outs of inlining. 155 Item 31: Minimize compilation dependencies between files. 161 Chapter 6: Inheritance and Object-Oriented Design 170 Item 32: Make sure public inheritance models “is-a.” 171 Item 33: Avoid hiding inherited names. 177 Item 34: Differentiate between inheritance of interface and inheritance of implementation. 182 Item 35: Consider alternatives to virtual functions. 190 Item 36: Never redefine an inherited non-virtual function. 199 Item 37: Never redefine a function’s inherited default parameter value. 201 Item 38: Model “has-a” or “is-implemented-in-terms- of” through composition. 205 Item 39: Use private inheritance judiciously. 208 Item 40: Use multiple inheritance judiciously. 213 Chapter 7: Templates and Generic Programming 220 Item 41: Understand implicit interfaces and compile-time polymorphism. 220 Item 42: Understand the two meanings of typename. 224 Item 43: Know how to access names in templatized base classes. 228 Item 44: Factor parameter-independent code out of templates. 233 Item 45: Use member function templates to accept “all compatible types.” 239 Item 46: Define non-member functions inside templates when type conversions are desired. 243 Item 47: Use traits classes for information about types. 247 Item 48: Be aware of template metaprogramming. 254 Chapter 8: Customizing new and delete 260 Item 49: Understand the behavior of the new-handler. 261 Item 50: Understand when it makes sense to replace new and delete. 268 Item 51: Adhere to convention when writing new and delete. 273 Item 52: Write placement delete if you write placement new. 277 Chapter 9: Miscellany 283 Item 53: Pay attention to compiler warnings. 283 Item 54: Familiarize yourself with the standard library, including TR1. 284 Item 55: Familiarize yourself with Boost. 290 Appendix A: Beyond Effective C++ 294 Appendix B: Item Mappings Between Second and Third Editions 298 Index 301 A 301 B 301 C 302 D 304 E 305 F 308 G 309 H 309 I 309 J 310 K 311 L 311 M 311 N 312 O 312 P 313 R 314 S 315 T 316 U 317 V 317 W 318 X 318 Z 318 “Every C++ professional needs a copy of
Effective C++. It is an absolute must-read for anyone thinking of doing serious C++ development. If you’ve never read
Effective C++ and you think you know everything about C++, think again.”
—
Steve Schirripa, Software Engineer, Google “C++ and the C++ community have grown up in the last fifteen years, and the third edition of
Effective C++ reflects this. The clear and precise style of the book is evidence of Scott’s deep insight and distinctive ability to impart knowledge.”
—
Gerhard Kreuzer, Research and Development Engineer, Siemens AG
The first two editions of Effective C++ were embraced by hundreds of thousands of programmers worldwide. The reason is clear: Scott Meyers’ practical approach to C++ describes the rules of thumb used by the experts — the things they almost always do or almost always avoid doing — to produce clear, correct, efficient code.
The book is organized around 55 specific guidelines, each of which describes a way to write better C++. Each is backed by concrete examples. For this third edition, more than half the content is new, including added chapters on managing resources and using templates. Topics from the second edition have been extensively revised to reflect modern design considerations, including exceptions, design patterns, and multithreading.
Important features of Effective C++ include:
- Expert guidance on the design of effective classes, functions, templates, and inheritance hierarchies.
- Applications of new “TR1” standard library functionality, along with comparisons to existing standard library components.
- Insights into differences between C++ and other languages (e.g., Java, C#, C) that help developers from those languages assimilate “the C++ way” of doing things.
The Barnes & Noble Review Since early in the 90s, working C++ programmers have relied on Scott Meyers s Effective C++ to dramatically improve their skills. But the state-of-the-art has moved forward dramatically since Meyers last updated this book in 1997. (For instance, there s now STL. Design patterns. Even new functionality being added through TR1 and Boost.) So Meyers has done a top-to-bottom rewrite, identifying the 55 most valuable techniques you need now to be exceptionally effective with C++. Over half of this edition s content is new. Templates broadly impact C++ development, and you ll find them everywhere. There s extensive coverage of multithreaded systems. There s an entirely new chapter on resource management. You ll find substantial new coverage of exceptions. Much is gained, but nothing s lost: You ll find the same depth of practical insight that first made Effective C++ a classic all those years ago. Bill Camarda, from the July 2005 (