Home > Store > Programming > C/C++

larger cover

Add To My Wish List

More Effective C++: 35 New Ways to Improve Your Programs and Designs

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

  • Description
  • Downloads
  • Extras
  • Reviews
  • Sample Content
  • Updates

Product Author Bios

Scott Meyers is one of the world's foremost authorities on C++, providing training and consulting services to clients worldwide. He is the author of the best-selling Effective C++ series of books (Effective C++, More Effective C++, and Effective STL) and of the innovative Effective C++ CD. He is consulting editor for Addison Wesley's Effective Software Development Series and serves on the Advisory Board for The C++ Source (http://www.artima.com/cppsource). He holds a Ph.D. in Computer Science from Brown University. His web site is http://www.aristeia.com.



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:

  • 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.

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++.

Related Article

More Effective C++ at 30 (Printings)

Items

Item 5
Item 9
Item 10
Item 33

Audio

meyers.wav

auto_ptr

The More Effective C++ auto_ptr

Customer Reviews

25 of 27 people found the following review helpful
5.0 out of 5 stars Terrific coverage of advanced C++ techniques, December 18, 1999
This review is from: More Effective C++: 35 New Ways to Improve Your Programs and Designs (Paperback)
While Meyers' first book, _Effective C++_, described fundamental concepts of C++, this book covers substantially more advanced techniques. These are not the heavily-designed strategies described in _Design Patterns_ or _Advanced C++: Programming Styles and Idioms_, but more lightweight and fundamental C++ features, including the specifics of memory allocation, exception handling, stack-based classes, and operator overloading. These are features of C++ which can be ignored at first but soon become key everday programming elements and important design considerations once well understood.

The material covered here separates the casual or novice C++ hobbyist from the true programmer.

Help other customers find the most helpful reviews 
Was this review helpful to you? Yes No


20 of 22 people found the following review helpful
4.0 out of 5 stars Really good book, but may be it's not a must for everybody, July 30, 1998
This review is from: More Effective C++: 35 New Ways to Improve Your Programs and Designs (Paperback)
Yeah, Effective C++ is really a *must read* if you want to improve your current knowledge of C++. However, although interesting, I don't find this book a must because it explains things you will not probably use in your real life as a programmer. If you already have Effective C++, both Stroustup, and/or Coplien's "Advanced C++ Programming Styles and Idioms" and/or Murray's "C++ Strategies and Tactics", I don't think you should get it unless you do not sleep at nights or you want to know absolutely everything about C++. However, it is a good book, so if you are not concerned about money, get it and read it, but get first the other ones I said.
Help other customers find the most helpful reviews 
Was this review helpful to you? Yes No


16 of 17 people found the following review helpful
5.0 out of 5 stars If you are serious about C++..., October 26, 1999
This review is from: More Effective C++: 35 New Ways to Improve Your Programs and Designs (Paperback)
...this book is for you. Both "50 Specific Ways" and his second book "35 New Ways" have helped me bring my C++ programming up to the next level of understanding. After using C for more than 10 years and C++ for all but the first few of those years, there were still many small things that used to bug me. Problems with some of my constructors, strange constructs I'd discovered over the years but never 100% understood... Scott's books have not only cleared the field, but have brought to my attention many new things about objects and C++ I'd never previously considered.

One warning: I found that some items were too far above me when I first read through the books -- especially this second book, "35 New Ways..." However, once I'd finished reading the book, I started again right back at page 1, and my second (and 3rd, 4th...) reading made much more sense. There is a *lot* of helpful information packed into Scott's 85 items.

I recommend... Read more

Help other customers find the most helpful reviews 
Was this review helpful to you? Yes No


Share your thoughts with other customers:
 See all 50 customer reviews...

Praise For More Effective C++: 35 New Ways to Improve Your Programs and Designs

"This (More Effective C++) is an enlightening book on many aspects of C++: both the regions of the language you seldom visit, and the familiar ones you THOUGHT you understood. Only by understanding deeply how the C++ compiler interprets your code can you hope to write robust software using this language. This book is an invaluable resource for gaining that level of understanding. After reading this book, I feel like I've been through a code review with a master C++ programmer, and picked up many of his most valuable insights."
– Fred Wild, Vice President of Technology, Advantage Software Technologies

"This book (More Effective C++) includes a great collection of important techniques for writing programs that use C++ well. It explains how to design and implement the ideas, and what hidden pitfalls lurk in some obvious alternative designs. It also includes clear explanations of features recently added to C++. Anyone who wants to use these new features will want a copy of this book close at hand for ready reference."
– Christopher J. Van Wyk, Professor, Mathematics and Computer Science, Drew University

"(More Effective C++ is) Industrial strength C++ at its best. The perfect companion to those who have read Effective C++."
– Eric Nagler, C++ Instructor and Author, University of California Santa Cruz Extension

"More Effective C++ is a thorough and valuable follow-up to Scott's first book, Effective C++. I believe that every professional C++ developer should read and commit to memory the tips in both Effective C++ and More Effective C++. I've found that the tips cover poorly understood, yet important and sometimes arcane facets of the language. I strongly recommend this book, along with his first, to developers, testers, and managers ... everyone can benefit from his expert knowledge and excellent presentation."
– Steve Burkett, Software Consultant

Table of Contents

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

Introduction

These are heady days for C++ programmers. Commercially available less than a decade, C++ has nevertheless emerged as the language of choice for systems programming on nearly all major computing platforms. Companies and individuals with challenging programming problems increasingly embrace the language, and the question faced by those who do not use C++ is often when they will start, not if. Standardization of C++ is essentially complete, and the breadth and scope of the accompanying library -- which both dwarfs and subsumes that of C -- makes it possible to write rich, complex programs without sacrificing portability or implementing common algorithms and data structures from scratch. C++ compilers continue to proliferate, the features they offer continue to expand, and the quality of the code they generate continues to improve. Tools and environments for C++ development grow ever more abundant, powerful, and robust. Commercial libraries all but obviate the need to write code in many application areas.

As the language has matured and our experience with it has increased, our needs for information about it have changed. In 1990, people wanted to know what C++ was. By 1992, they wanted to know how to make it work. Now C++ programmers ask higher-level questions: How can I design my software so it will adapt to future demands? How can I improve the efficiency of my code without compromising its correctness or making it harder to use? How can I implement sophisticated functionality not directly supported by the language? In this book, I answer these questions and many others like them.

This book shows how to design and implement C++ software that is more effective: more likely to behave correctly; more robust in the face of exceptions; more efficient; more portable; makes better use of language features; adapts to change more gracefully; works better in a mixed-language environment; is easier to use correctly; is harder to use incorrectly. In short, software that's just better.

The material in this book is divided into 35 Items. Each Item summarizes the accumulated wisdom of the C++ programming community on a particular topic. Most Items take the form of guidelines, and the explanation accompanying each guideline describes why the guideline exists, what happens if you fail to follow it, and under what conditions it may make sense to violate the guideline anyway.

Items fall into several categories. Some concern particular language features, especially newer features with which you may have little experience. For example, Items 9 through 15 are devoted to exceptions. Other Items explain how to combine the features of the language to achieve higher-level goals. Items 25 through 31, for instance, describe how to constrain the number or placement of objects, how to create functions that act "virtual" on the type of more than one object, how to create "smart pointers," and more. Still other Items address broader topics; Items 16 through 24 focus on efficiency. No matter what the topic of a particular Item, each takes a no-nonsense approach to the subject. In More Effective C++, you learn how to use C++ more effectively. The descriptions of language features that make up the bulk of most C++ texts are in this book mere background information.

An implication of this approach is that you should be familiar with C++ before reading this book. I take for granted that you understand classes, protection levels, virtual and nonvirtual functions, etc., and I assume you are acquainted with the concepts behind templates and exceptions. At the same time, I don't expect you to be a language expert, so when poking into lesser-known corners of C++, I always explain what's going on.

The C++ in More Effective C++

The C++ I describe in this book is the language specified by the working papers of the ANSI/ISO standardization committee in the fall of 1995. In all likelihood, this means I use a few features your compilers don't yet support. Don't worry. The only "new" feature I assume you have is templates, and templates are now almost universally available. I use exceptions, too, but that use is largely confined to Items 9 through 15, which are specifically devoted to exceptions. If you don't have access to a compiler offering exceptions, that's okay. It won't affect your ability to take advantage of the material in the other parts of the book. Furthermore, you should read Items 9 through 15 even if you don't have support for exceptions, because those items examine issues you need to understand in any case.

I recognize that just because the standardization committee blesses a feature or endorses a practice, there's no guarantee that the feature is present in current compilers or the practice is applicable to existing environments. When faced with a discrepancy between theory (what the committee says) and practice (what actually works), I discuss both, though my bias is toward things that work. Because I discuss both, this book will aid you as your compilers approach conformance with the standard. It will show you how to use existing constructs to approximate language features your compilers don't yet support, and it will guide you when you decide to transform workarounds into newly- supported features.

Notice that I refer to your compilers -- plural. Different compilers implement varying approximations to the standard, so I encourage you to develop your code under at least two compilers. Doing so will help you avoid inadvertent dependence on one vendor's proprietary language extension or its misinterpretation of the standard. It will also help keep you away from the bleeding edge of compiler technology, i.e., from new features supported by only one vendor. Such features are often poorly implemented (buggy or slow -- frequently both), and upon their introduction, the C++ community lacks experience to advise you in their proper use. Blazing trails can be exciting, but when your goal is producing reliable code, it's often best to let others test the waters before jumping in.

There are two constructs you'll see in this book that may not be familiar to you. Both are relatively recent language extensions. Some compilers support them, but if your compilers don't, you can easily approximate them with features you do have.

The first construct is the bool type, which has as its values the keywords true and false. If your compilers haven't implemented bool, there are two ways to approximate it. One is to use a global enum:

enum bool { false, true };

This allows you to overload functions on the basis of whether they take a bool or an int, but it has the disadvantage that the built-in comparison operators (i.e., ==, <, >=, etc.) still return ints. As a result, code like the following will not behave the way it's supposed to:

void f(int);
void f(bool);

int x, y;
...

f( x < y );                             // calls f(int), but it
// should call f(bool)

The enum approximation may thus lead to code whose behavior changes when you submit it to a compiler that truly supports bool.

An alternative is to use a typedef for bool and constant objects for true and false:

typedef int bool;

const bool false = 0;
const bool true = 1;

This is compatible with the traditional semantics of C and C++, and the behavior of programs using this approximation won't change when they're ported to bool-supporting compilers.

Errata

Access errata at www.aristeia.com

 
Best Value

Book + eBook Bundle  $89.98  $53.99

Book Price $39.99
eBook Price $14.00
eBook formats included

Buy

This book includes free shipping!

Buy

Book  $49.99  $39.99

Usually ships in 24 hours.

This book includes free shipping!

Buy

eBook (Watermarked)  $39.99  $31.99

Includes EPUB, MOBI, and PDF
About eBook Formats

This eBook includes the following formats, accessible from your Account page after purchase:

ePubEPUBThe open industry format known for its reflowable content and usability on supported mobile devices.

MOBIMOBIThe eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

Adobe ReaderPDFThe 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 discretely watermarking it with your name, making it uniquely yours.

Purchase Reward: One Month Free Subscription
By completing any purchase on InformIT, you become eligible for an unlimited access one-month subscription to Safari Books Online.

Get access to thousands of books and training videos about technology, professional development and digital media from more than 40 leading publishers, including Addison-Wesley, Prentice Hall, Cisco Press, IBM Press, O'Reilly Media, Wrox, Apress, and many more. If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months. That's a total savings of $199.