Home > Store

C++ Strategies and Tactics

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

C++ Strategies and Tactics


  • Sorry, this book is no longer in print.
Not for Sale


  • Copyright 1993
  • Dimensions: 7" x 9-1/4"
  • Pages: 296
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-56382-7
  • ISBN-13: 978-0-201-56382-5

In chess, learning the rules for how the pieces move is simply the first step; to master the game, you must understand the strategies and tactics that guide each move. The same applies to C++. Knowing the right strategies helps you avoid the traps and work more effectively. Luminary Rob Murray helps beginning to intermediate C++ programmers take that next step by sharing his experience and advice.

Practical code examples are used throughout to illuminate useful programming strategies and warn against dangerous practices. To further ensure comprehension, each chapter ends with a list of the key ideas introduced in that chapter, along with questions to stimulate thought and discussion.

You'll begin by learning how to choose the right abstractions for your design, taking care to preserve the distinction between abstraction and implementation. You'll then look at the process of turning an abstraction into one or more C++ classes, with discussions ranging from high-level design strategies to low-level interface and implementation details.

Single and multiple inheritance are explored in depth, beginning with a discussion of where they fit in a design and followed by detailed examples that show how the concepts are used in practice. A separate chapter covers the techniques of building classes from which others can derive, and discusses the benefits - and costs - involved.

Rob Murray offers unprecedented insight into the new templates feature, beginning with the basics and walking you through several real-world examples. The author also describes a variety of specific techniques to make your programs faster, more reusable, and more robust. Exceptions are another new C++ feature; Murray gives advice on when they should - and should not - be used. The book concludes with a look at the process of moving a project from C to C++, exploring the human issues as well as the technical ones.


Sample Content

Table of Contents


0. Introduction.

A Note about The Code Examples.

A Road Map.


The Language Rules.

1. Abstraction.

A Telephone Number Abstraction.

Relationships Between Abstractions.

Worrying about the Boundary Conditions.

Designing with CRC Cards.

In Short.


2. Classes.



Public Data.

Implicit Type Conversions.

Overloaded Operators: Members or Nonmembers?

Overloading, Defaults, and Ellipsis.


Returning References.

Static Constructors.

In Short.

Questions. CHAPTER = 3. Handles.

String Class.

Avoiding Copies with Use Counts.

Avoiding Recompilations: The Cheshire Cat.

Using Handles to Hide the Design.

Multiple Implementations.

Handles as Objects.


In Short.


4. Inheritance.

The is-a Relationship.

Public Inheritance.

Private Inheritance.

Protected Inheritance.

Conformance to Base Class Abstractions.

Pure Virtual Functions.

Inheritance Details and Traps.

In Short.


5. Multiple Inheritance.

Multiple Inheritance as Set Intersection.

Virtual Base Classes.

Some Multiple Inheritance Details.

In Short.


6. Designing for Inheritance.

The Protected Interface.

Should You Design for Inheritance?

Design for Inheritance: Some Examples.


In Short.


7. Templates.

A Pair Class Template.

Some Template Details.

Template Instantiation.

Smart Pointers.

Expression Arguments to Templates.

Function Templates.

In Short.


8. Advanced Templates.

Container Classes Using Templates.

Example: A Block Class.

Detailed Block Design Issues.

Containers with Iterators: A List Class.

Iterator Design Issues.

Performance Issues.

Constraints on Template Arguments.

Template Specializations.

In Short.


9. Reusability.

Discovery and Acquisition.


Memory Management.

Alternative Memory Allocation Schemes.

Passing Arguments to Operator New.

Managing External Resources.

Finding Memory Bugs.

Name Collisions.


Don't Guess, Measure!


Bottlenecks in Dynamic Memory Allocation.


Tiemann's Law.

In Short.


10. Exceptions.

A Disclaimer.

Why Exceptions?

An Example Exception.

Exceptions Should Be Exceptional.

Understanding Exceptions.

Blame Assessment.

Designing the Exception Object.

In Short.


11. Moving Your Project to C++.

Choosing C++.

Adopting C++.

Design and Implementation.

Developing an Asset Base.

A Closing Thought.

In Short.


Index. 0201563827T04062001


In the hands of an expert, C++ helps designers and programmers build systems that are modular, maintainable, and fast. To the novice, however, the size of the language can be intimidating. There are a lot of features in C++ and it takes some experience to learn which ones are appropriate for any situation.

This book is intended to enhance and expedite that learning process. Most successful C++ programmers cannot recite chapter and verse from the language rules; instead, they have acquired a set of idioms and techniques that have worked well for them. Our goal is to help the C++ novice learn those idioms that have been most useful in practice. We also point out some of the most common pitfalls.

We do not try to cover the entire language and we leave the ultra-precise definitions of language semantics to the reference manuals. Instead, we concentrate on helping the reader build programs that can be understood by someone who is not a C++ language lawyer. We not only discuss techniques for making programs elegant and fast; we also show how to make them easier to understand and maintain.

Acknowledgements Almost none of the ideas and programming idioms in this book are my invention. My goal has been to present, in a way that allows novice C++ programmers to learn them quickly, what I consider to be the most important strategies and tactics I have learned from others in the eight years I have been using C++. Some of these lessons were learned by studying actual development projects as they moved from C to C++; others came from discussions with talented individuals.

Many of the best ideas on templates and library design, including the ideas behind many of the container classes in this book, came from classes in the USL Standard Components that were originally designed by Martin Carroll, Andrew Koenig, and Jonathan Shopiro. I claim exclusive ownership of any errors in my versions. Andrew Koenig was a valuable resource as the local C++ language lawyer. The participants in the "C++ Strategies and Tactics" seminars I presented at several conferences helped inspire this book and refine its ideas. Other important ideas came from Tom Cargill, John Carolan, Jim Coplien, Mark Linton, Gerald Schwarz, and of course Bjarne Stroustrup, who also invented the C++ programming language that made the book possible in the first place.

Brian Kernighan read several drafts of this book, and his excellent feedback has been a lot of help. I would also like to thank David Annatone, Steve Buroff, Tom Cargill, Bill Hopkins, Cay Horstman, Lorraine Juhl, Peter Juhl, Stan Lippman, Dennis Mancl, Scott Meyers, Barbara Moo, Lorraine Weisbrot Murray, Bjarne Stroustrup, Clovis Tondo, Steve Vinoski, and Christopher Van Wyk for their comments on early drafts of this book. Lorraine Weisbrot Murray also contributed the encouragement, understanding, support, and love that helped make the entire effort feasible.

Rob Murray



Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership