HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
More than 150,000 copies in print!
Praise for Scott Meyers’ first book, Effective C++:
“I heartily recommend Effective C++ to anyone who aspires to mastery of C++ at the intermediate level or above.”
– The C/C++ User’s Journal
From the author of the indispensable Effective C++, here are 35 new ways to improve your programs and designs. Drawing on years of experience, Meyers explains how to write software that is more effective: more efficient, more robust, more consistent, more portable, and more reusable. In short, how to write C++ software that’s just plain better.
More Effective C++ includes:
More Effective C++ is filled with pragmatic, down-to-earth advice you’ll use every day. Like Effective C++ before it, More Effective C++ is essential reading for anyone working with C++.
Acknowledgments xi
Introduction 1
Basics 9
Item 1: Distinguish between pointers and references. 9
Item 2: Prefer C++-style casts. 12
Item 3: Never treat arrays polymorphically. 16
Item 4: Avoid gratuitous default constructors. 19
Operators 24
Item 5: Be wary of user-defined conversion functions. 24
Item 6: Distinguish between prefix and postfix forms of increment and decrement operators. 31
Item 7: Never overload &&, ||, or ,. 35
Item 8: Understand the different meanings of new and delete. 38
Exceptions 44
Item 9: Use destructors to prevent resource leaks. 45
Item 10: Prevent resource leaks in constructors. 50
Item 11: Prevent exceptions from leaving destructors. 58
Item 12: Understand how throwing an exception differs from passing a parameter or calling a virtual function. 61
Item 13: Catch exceptions by reference. 68
Item 14: Use exception specifications judiciously. 72
Item 15: Understand the costs of exception handling. 78
Efficiency 81
Item 16: Remember the 80-20 rule. 82
Item 17: Consider using lazy evaluation. 85
Item 18: Amortize the cost of expected computations. 93
Item 19: Understand the origin of temporary objects. 98
Item 20: Facilitate the return value optimization. 101
Item 21: Overload to avoid implicit type conversions. 105
Item 22: Consider using op= instead of stand-alone op. 107
Item 23: Consider alternative libraries. 110
Item 24: Understand the costs of virtual functions, multiple inheritance, virtual base classes, and RTTI. 113
Techniques 123
Item 25: Virtualizing constructors and non-member functions. 123
Item 26: Limiting the number of objects of a class. 130
Item 27: Requiring or prohibiting heap-based objects. 145
Item 28: Smart pointers. 159
Item 29: Reference counting. 183
Item 30: Proxy classes. 213
Item 31: Making functions virtual with respect to more than one object. 228
Miscellany 252
Item 32: Program in the future tense. 252
Item 33: Make non-leaf classes abstract. 258
Item 34: Understand how to combine C++ and C in the same program. 270
Item 35: Familiarize yourself with the language standard. 277
Recommended Reading 285
An auto_ptr Implementation 291
General Index 295
Index of Example Classes, Functions, and Templates 313