C++ Primer (2nd Edition)
I was both pleasantly surprised and gratified to find the first edition of the C++ Primer enthusiastically received by the C++ community.  When my editor suggested a second edition, my first reaction was, "What?  Already?"  However, the conditions seemed as propitious as those surrounding the first edition:  my wife and I were expecting a child again (this time a girl, Anna Rachel); I was again working long hours trying to get out a new release of the compiler (this time, Release 3.0); and again, the C++ language had significantly evolved (this time, the template facility and a published exception handling specification).  Okay, then.  "But I want it to be a better edition, not just an update," I told my editor, my wife, my colleagues at work, and just about anyone who would listen.  "Oh," they said, their voice muted, eyes cast downward to the street, carpet, meal.  "Well, don't ruin it," they advised.BACKGROUND ON  C++The C++ programming language was developed at AT&T; Bell Laboratories in the early 1980s by Bjarne Stroustrup.  It is an evolution of the C programming language, which extends C in three important ways:It provides support for creating and using data abstractions It provides support for object-oriented design and programming It provides various nice improvements over existing C constructs  all while retaining C's simplicity of expression and speed of execution.C++ is already widely available and is in wide use for real application and systems development.  Within six months of its initial release from AT&T; in late 1985, there were commercial ports of C++ available on over 24 systems, ranging from PCs to large mainframes.  Since then, more ports have been made, and C++ is now available directly from many computer vendors.  In 1988 the first native compilers were produced for the PC and workstation markets.  Additionally, large-scale libraries and program support environments have begun to appear.  The maturation of the C++ language is attested to by two recent events:  the formation of an ANSI C++ committee and the publication of THE ANNOTATED C++ REFERENCE MANUAL by Ellis and Stroustrup, which serves as the baseline document for the C++ ANSI committee.  Papers documenting user experience with C++ have appeared in various conferences (there are now two annual conferences devoted exclusively to C++) and technical publications.STRUCTURE OF THIS BOOK This book provides a comprehensive introduction to C++ as reflected in its latest release, Release 3.0, and the baseline ANSI C++ document, THE ANNOTATED C++ REFERENCE MANUAL  by Ellis and Stroustrup.  Additionally, it provides a consciously tutorial appraoch to describingthe C++ language.  Knowledge of C is not assumed, although familiarity with some modern, block structured language is.  This book is intended as a first book on C++; it is not intended as a first book on programming!Much of the power of C++ comes from its support for new ways of programming and new ways of thinking about programming problems.  Learning to use C++ effectively, therefore, requires more than simply learning a new set of syntax and semantics.  To facilitate this larger learning, the book is organized around a series of extended examples.  These examples are used both to introduce the details of various language features, and to motivate them as well.  By learning language features in the context of a full example, it becomes clear why such features are useful, providing a sense of when and how one would make use of them for real world problem solving.  Additionally, this focus on examples, which can and should be executed, allows early use of concepts that will be explained more fully as the reader's knowledge base is built up.  Early examples can and do contain simple uses of fundamental C++ concepts, giving a flavor for the kinds of programming one can do in C++ without requiring complete understanding of the details of design and implementation.Fundamental to C++ are various facilities that allow the user to extend the language itself by defining new data types that then can be used with the flexibility and simplicity of built-in data types.  The first step to mastery is to understand the base language itself.  Chapters 0 through 4 focus on the language at this level, while Chapters 5 through 9 extend the discussion of the facilities which support creation of user-defined types.  Chapter 10 provides a tutorial illustration of the process of object-oriented design in C++.Chapter 0 introduces the essential elements of a C++ program and the details of how to get a C++ program entered and executed.  Data types, expressions and statements are the subject of Chapters 1 and 2.  Chapter 1 includes a discussion and example of the C++ class introducing this fundamental notion that will be expanded on throughout the book.  Chapter 3 introduces functions, the notion of program scope, and the run-time allocation of variables through the use of a program's free store.  Proficient programmers--and especially C prgrammers--may be tempted to skip these chapters.  Don't.  New concepts are included throughout these sections and even the most experienced C programmer will benefit from skimming the material and working through the examples in the text and the exercises.Chapter 4 extends the discussion to encompass function overloading and the definition and use of template functions.  Overloading allows multiple function instances that provide a common operation (but require differing implementations) to share a common name.  The programmer can write put ( ) rather than putc ( ) or puts ( ) , for example, and trust the compiler to resolve the call to the intended instance.  A template function provides a prescription for the automatic generation of an infinite set of function instances varying by type but whose implementation remains invariant.Chapters 5 and 6 focus on the class mechanism and how it supports the design and implementation of abstract data types.  By creating new types to describe the problem domain, C++ allows the programmer to write applications with much less concern for the various bookkeeping aspects that make programming tedious.  The implementation of types fundamental to the application can be implemented once and reused, allowing the programmer to concentrate on the problem rather than the details of the implementation.  Facilities for encapsulating the data can dramatically simplify subsequent maintenance and change.Chapter 7 examines the definition and use of the template class facility.  Template classes facilitate the development of extensive class libararies.  As with a template function, a template class provides a prescription for the automatic generation of an infinite set of class instances varying by type but whose implementation remains invariant.Object-oriented programming and the facilities in C++ that support it are the topics of Chapters 8 and 9.  Chapter 8 introduces inheritance. Through inheritance, the programmer can capture type relationships that are interdependent.  The classic example is that of shapes.  All shapes share certain attributes:  location on the plane, logic to rotate the shape, draw the shape, etc.  Inheritance allows these common attributes to be shared from the application's viewpoint while the implementation of each specific shape need worry only about providing definitions for those attribures that actually differ from one shape to the next.  Fundamental to object-oriented approaches is the ability to choose at run time which exat function will be invoked.  For example, at run time we must be able to tell a shape to rotate and know that the appropriate logic for a circle or square will be invoked depending on the actual type of the shape that is being rotated.  In C++ this is handled through the virtual function mechanism, which is the topic of Chapter 9.  Chapter 9 also introduces the more complicated inheritance hierarchies that are made possible through virtual base classes.  Chapter 10 provides a tutorial illustration of object-oriented design using C++.CHANGES TO THE SECOND EDITIONThe changes to the second edition fall into four general categories:  Coverage of new features added to the language: the template facility and exception handling. Adjustments in the existing test to reflect refinements, changes, and extensions in the existing language. An example of a  refinement is the small change in the rules for the initialization of a reference.  This in turn modified slightly the argument-matching algorithm forthe resolution of a call of an overloaded function.  An example of a large change in the language is the introduction of nested types within classes.  (A discussion of how nested types were "reintroduced" into C++ can be found in my article "Nested Types in C++," published in the C++ Journal, Fall, 1