Home > Store

Effective C++ Digital Collection: 140 Ways to Improve Your Programming

Register your product to gain access to bonus material or receive a coupon.

Effective C++ Digital Collection: 140 Ways to Improve Your Programming

eBook (Watermarked)

  • Your Price: $76.79
  • List Price: $95.99
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® 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.


  • Copyright 2005
  • Edition: 1st
  • eBook (Watermarked)
  • ISBN-10: 0-13-306862-5
  • ISBN-13: 978-0-13-306862-7

Scott Meyers’s seminal C++ books–Effective C++, More Effective C++, and Effective STL–have been immensely helpful to hundreds of thousands of C++ programmers. All three are finally available together in this eBook collection.

Effective C++ has been embraced by hundreds of thousands of programmers worldwide. The reason is clear: Scott Meyers’s practical approach to C++ describes the rules of thumb used by the experts 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.

In More Effective C++, Meyers presents 35 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.

In Effective STL, Meyers goes beyond describing what's in the STL to show you how to use it. Each of the book’s 50 guidelines is backed by Meyers’s legendary analysis and incisive examples, so you’ll learn not only what to do, but also when to do it–and why.

Together in this collection, these books include the following important features:

  • 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.
  • Proven methods for improving program efficiency, including incisive examinations of the time/space costs of C++ language features
  • Comprehensive descriptions of advanced techniques used by C++ experts, including placement new, virtual constructors, smart pointers, reference counting, proxy classes, and double-dispatching
  • Examples of the profound impact of exception handling on the structure and behavior of C++ classes and functions
  • Practical treatments of new language features, including bool, mutable, explicit, namespaces, member templates, the Standard Template Library, and more. If your compilers don’t yet support these features, Meyers shows you how to get the job done without them.
  • Advice on choosing among standard STL containers (like vector and list), nonstandard STL containers (like hash_set and hash_map), and non-STL containers (like bitset).
  • Techniques to maximize the efficiency of the STL and the programs that use it.
  • Insights into the behavior of iterators, function objects, and allocators, including things you should not do.
  • Guidance for the proper use of algorithms and member functions whose names are the same (e.g., find), but whose actions differ in subtle (but important) ways.
  • Discussions of potential portability problems, including straightforward ways to avoid them.

Sample Content

Table of Contents

Effective C++


Introduction 1A

Chapter 1: Accustoming Yourself to C++ 11A

Item 1: View C++ as a federation of languages. 11A

Item 2: Prefer consts, enums, and inlines to #defines. 13A

Item 3: Use const whenever possible. 17A

Item 4: Make sure that objects are initialized before they’re used. 26A

Chapter 2: Constructors, Destructors, and Assignment Operators 34A

Item 5: Know what functions C++ silently writes and calls. 34A

Item 6: Explicitly disallow the use of compiler-generated functions you do not want. 37A

Item 7: Declare destructors virtual in polymorphic base classes. 40A

Item 8: Prevent exceptions from leaving destructors. 44A

Item 9: Never call virtual functions during construction or destruction. 48A

Item 10: Have assignment operators return a reference to *this. 52A

Item 11: Handle assignment to self in operator=. 53A

Item 12: Copy all parts of an object. 57A

Chapter 3: Resource Management 61A

Item 13: Use objects to manage resources. 61A

Item 14: Think carefully about copying behavior in resourcemanaging classes. 66A

Item 15: Provide access to raw resources in resourcemanaging classes. 69A

Item 16: Use the same form in corresponding uses of new and delete. 73A

Item 17: Store newed objects in smart pointers in standalone statements. 75A

Chapter 4: Designs and Declarations 78A

Item 18: Make interfaces easy to use correctly and hard to use incorrectly. 78A

Item 19: Treat class design as type design. 84A

Item 20: Prefer pass-by-reference-to-const to pass-by-value. 86A

Item 21: Don’t try to return a reference when you must return an object. 90A

Item 22: Declare data members private. 94A

Item 23: Prefer non-member non-friend functions to member functions. 98A

Item 24: Declare non-member functions when type conversions should apply to all parameters. 102A

Item 25: Consider support for a non-throwing swap. 106A

Chapter 5: Implementations 113A

Item 26: Postpone variable definitions as long as possible. 113A

Item 27: Minimize casting. 116A

Item 28: Avoid returning “handles” to object internals. 123A

Item 29: Strive for exception-safe code. 127A

Item 30: Understand the ins and outs of inlining. 134A

Item 31: Minimize compilation dependencies between files. 140A

Chapter 6: Inheritance and Object-Oriented Design 149A

Item 32: Make sure public inheritance models “is-a.” 150A

Item 33: Avoid hiding inherited names. 156A

Item 34: Differentiate between inheritance of interface and inheritance of implementation. 161A

Item 35: Consider alternatives to virtual functions. 169A

Item 36: Never redefine an inherited non-virtual function. 178A

Item 37: Never redefine a function’s inherited default parameter value. 180A

Item 38: Model “has-a” or “is-implemented-in-terms-of” through composition. 184A

Item 39: Use private inheritance judiciously. 187A

Item 40: Use multiple inheritance judiciously. 192A

Chapter 7: Templates and Generic Programming 199A

Item 41: Understand implicit interfaces and compile-time polymorphism. 199A

Item 42: Understand the two meanings of typename. 203A

Item 43: Know how to access names in templatized base classes. 207A

Item 44: Factor parameter-independent code out of templates. 212A

Item 45: Use member function templates to accept “all compatible types.” 218A

Item 46: Define non-member functions inside templates when type conversions are desired. 222A

Item 47: Use traits classes for information about types. 226A

Item 48: Be aware of template metaprogramming. 233A

Chapter 8: Customizing new and delete 239A

Item 49: Understand the behavior of the new-handler. 240A

Item 50: Understand when it makes sense to replace new and delete. 247A

Item 51: Adhere to convention when writing new and delete. 252A

Item 52: Write placement delete if you write placement new. 256A

Chapter 9: Miscellany 262A

Item 53: Pay attention to compiler warnings. 262A

Item 54: Familiarize yourself with the standard library, including TR1. 263A

Item 55: Familiarize yourself with Boost. 269A

Appendix A: Beyond Effective C++ 273A

Appendix B: Item Mappings Between Second and Third Editions 277A

Index 280A


More Effective C++


Introduction 1B

Basics 9B

Item 1: Distinguish between pointers and references. 9B

Item 2: Prefer C++-style casts. 12B

Item 3: Never treat arrays polymorphically. 16B

Item 4: Avoid gratuitous default constructors. 19B

Operators 24B

Item 5: Be wary of user-defined conversion functions. 24B

Item 6: Distinguish between prefix and postfix forms of increment and decrement operators. 31B

Item 7: Never overload &&, ||, or ,. 35B

Item 8: Understand the different meanings of new and delete. 38B

Exceptions 44B

Item 9: Use destructors to prevent resource leaks. 45B

Item 10: Prevent resource leaks in constructors. 50B

Item 11: Prevent exceptions from leaving destructors. 58B

Item 12: Understand how throwing an exception differs from passing a parameter or calling a virtual function. 61B

Item 13: Catch exceptions by reference. 68B

Item 14: Use exception specifications judiciously. 72B

Item 15: Understand the costs of exception handling. 78B

Efficiency 81B

Item 16: Remember the 80-20 rule. 82B

Item 17: Consider using lazy evaluation. 85B

Item 18: Amortize the cost of expected computations. 93B

Item 19: Understand the origin of temporary objects. 98B

Item 20: Facilitate the return value optimization. 101B

Item 21: Overload to avoid implicit type conversions. 105B

Item 22: Consider using op= instead of stand-alone op. 107B

Item 23: Consider alternative libraries. 110B

Item 24: Understand the costs of virtual functions, multiple inheritance, virtual base classes, and RTTI. 113B

Techniques 123B

Item 25: Virtualizing constructors and non-member functions. 123B

Item 26: Limiting the number of objects of a class. 130B

Item 27: Requiring or prohibiting heap-based objects. 145B

Item 28: Smart pointers. 159B

Item 29: Reference counting. 183B

Item 30: Proxy classes. 213B

Item 31: Making functions virtual with respect to more than one object. 228B

Miscellany 252B

Item 32: Program in the future tense. 252B

Item 33: Make non-leaf classes abstract. 258B

Item 34: Understand how to combine C++ and C in the same program. 270B

Item 35: Familiarize yourself with the language standard. 277B

Recommended Reading 285B

An auto_ptr Implementation 291B

General Index 295B

Index of Example Classes, Functions, and Templates 313B


Effective STL


Introduction 1C

Chapter 1: Containers 11C

Item 1: Choose your containers with care. 11C

Item 2: Beware the illusion of container-independent code. 15C

Item 3: Make copying cheap and correct for objects in containers. 20C

Item 4: Call empty instead of checking size() against zero. 23C

Item 5: Prefer range member functions to their single-element counterparts. 24C

Item 6: Be alert for C++’s most vexing parse. 33C

Item 7: When using containers of newed pointers, remember to delete the pointers before the container is destroyed. 36C

Item 8: Never create containers of auto_ptrs. 40C

Item 9: Choose carefully among erasing options. 43C

Item 10: Be aware of allocator conventions and restrictions. 48C

Item 11: Understand the legitimate uses of custom allocators. 54C

Item 12: Have realistic expectations about the thread safety of STL containers. 58C

Chapter 2: vector and string 63C

Item 13: Prefer vector and string to dynamically allocated arrays. 63C

Item 14: Use reserve to avoid unnecessary reallocations. 66C

Item 15: Be aware of variations in string implementations. 68C

Item 16: Know how to pass vector and string data to legacy APIs. 74C

Item 17: Use “the swap trick” to trim excess capacity. 77C

Item 18: Avoid using vector<bool>. 79C

Chapter 3: Associative Containers 83C

Item 19: Understand the difference between equality and equivalence. 83C

Item 20: Specify comparison types for associative containers of pointers. 88C

Item 21: Always have comparison functions return false for equal values. 92C

Item 22: Avoid in-place key modification in set and multiset. 95C

Item 23: Consider replacing associative containers with sorted vectors. 100C

Item 24: Choose carefully between map::operator[] and map::insert when efficiency is important. 106C

Item 25: Familiarize yourself with the nonstandard hashed containers. 111C

Chapter 4: Iterators 116C

Item 26: Prefer iterator to const_iterator, reverse_iterator, and const_reverse_iterator. 116C

Item 27: Use distance and advance to convert a container’s const_iterators to iterators. 120C

Item 28: Understand how to use a reverse_iterator’s base iterator. 123C

Item 29: Consider istreambuf_iterators for character-bycharacter input. 126C

Chapter 5: Algorithms 128C

Item 30: Make sure destination ranges are big enough. 129C

Item 31: Know your sorting options. 133C

Item 32: Follow remove-like algorithms by erase if you really want to remove something. 139C

Item 33: Be wary of remove-like algorithms on containers of pointers. 143C

Item 34: Note which algorithms expect sorted ranges. 146C

Item 35: Implement simple case-insensitive string comparisons via mismatch or lexicographical_compare. 150C

Item 36: Understand the proper implementation of copy_if. 154C

Item 37: Use accumulate or for_each to summarize ranges. 156C

Chapter 6: Functors, Functor Classes, Functions, etc. 162C

Item 38: Design functor classes for pass-by-value. 162C

Item 39: Make predicates pure functions. 166C

Item 40: Make functor classes adaptable. 169C

Item 41: Understand the reasons for ptr_fun, mem_fun, and mem_fun_ref. 173C

Item 42: Make sure less<T> means operator<. 177C

Chapter 7: Programming with the STL 181C

Item 43: Prefer algorithm calls to hand-written loops. 181C

Item 44: Prefer member functions to algorithms with the same names. 190C

Item 45: Distinguish among count, find, binary_search, lower_bound, upper_bound, and equal_range. 192C

Item 46: Consider function objects instead of functions as algorithm parameters. 201C

Item 47: Avoid producing write-only code. 206C

Item 48: Always #include the proper headers. 209C

Item 49: Learn to decipher STL-related compiler diagnostics. 210C

Item 50: Familiarize yourself with STL-related web sites. 217C

Bibliography 225C

Appendix A: Locales and Case-Insensitive String Comparisons 229C

Appendix B: Remarks on Microsoft’s STL Platforms 239C

Index 245C


Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020