This book covers the C++ standard, the international standard published as ISO/IEC 14882:1998(E), Programming LanguagesC++
, plus Technical Corrigendum 1. Many implementations of C++ extend the language and standard library. Except for brief mentions of language and library extensions in the appendixes, this book covers only the standard. The standard library is largeit includes strings, containers, common algorithms, and much morebut it omits much that is commonplace in computing today: concurrency, network protocols, database access, graphics, windows, and so on. See for information about nonstandard libraries that provide additional functionality.
This book is a reference. It is not a tutorial. Newcomers to C++ might find portions of this book difficult to understand. Although each section contains some advice on idioms and the proper use of certain language constructs, the main focus is on the reference material. Visit http://www.tempest-sw.com/cpp/ for links to sites and lists of books that are better suited for beginners.
Structure of This Book
This book is divided into two interleaved sections that cover the language and the library, and a section of appendixes. Roughly speaking, the language is the part of C++ that does not require any additional #include
headers or files. The library is the part of C++ that is declared in the standard headers.
is a reference for the preprocessor.
present an overview of the library and introduce the topics that span individual headers.
Sometimes, information is duplicated, especially in . My goal has been to present information when you need it, where you need it. I tried to balance the need for a single, clear, complete description of each language feature with the desire to reduce the number of cross references you must chase before you can understand that language feature.
Here are more detailed descriptions of each chapter.
describes the basic rules for the C++ language: character sets, tokens, literals, and so on.
describes how objects, types, and namespaces are declared and how names are looked up.
describes operators, precedence, and type casts.
describes all the C++ statements.
describes function declarations and definitions, overload resolution, argument passing, and related topics.
describes classes (and unions and structures), members, virtual functions, inheritance, accessibility, and multiple inheritance.
describes class and function template declarations, definitions, instantiations, specializations, and how templates are used.
introduces the standard library and discusses some overarching topics, such as traits and allocators.
introduces the I/O portion of the standard library. Topics include formatted and unformatted I/O, stream buffers, and manipulators.
introduces the suite of container class templates, their iterators, and generic algorithms. This is the portion of the library that has traditionally been called the Standard Template Library (STL).
is an alphabetical reference for the preprocessor, which is part of the language, but with a distinct set of syntactic and semantic rules.
is an alphabetical reference for the language and grammar. Backus-Naur Form (BNF) syntax descriptions are given for each keyword and other language elements, with pointers to the first seven chapters for the main reference material.
is a reference for the entire standard library, organized alphabetically by header, and alphabetically by name within each header section.
describes ways that some compilers extend the language: to satisfy customer need, to meet platform-specific requirements, and so on.
).
The defines some words and phrases used throughout this book and in the C++ community.
About the Examples
Whenever possible, the examples in this book are complete, compilable programs. You can tell which examples fall into this category because they start with #include
directives and contain a main( )
function. You can download these examples as text files from the book's web site at http://www.tempest-sw.com/cpp/ or from O'Reilly's catalog page for this book: http://www.oreilly.com/catalog/cplsian/.
Most examples are shortened to eliminate excess code that might interfere with the clarity of the example. In particular, these examples are fragments that lack a main
function. Sometimes, an ellipsis indicates missing code, such as a function body. In other cases, the omissions are clear from the context. Most abbreviated examples have complete and compilable versions available for download.
All of the examples have been checked with several different compilers, including Comeau Computing's compiler with the Dinkumware standard library (widely acknowledged as the most complete and correct implementations of the C++ standard). Not all compilers can compile all the examples due to limitations and bugs in the compilers and libraries. For best results, try to work with the latest version of your compiler. Recent releases of several major compilers have made dramatic progress toward conformance with the standard. When possible, I have tried to alter the example files to work around the bugs without interfering with the intent of the example.
I have checked all the examples with the following compilers:
Linux
Borland Kylix 3.0
Comeau 4.3.0.1
GNU 3.2
Intel 7.0
Microsoft Windows
Conventions Used in This Book
This book uses the following conventions:
Constant Width
Used for identifiers and symbols, including all keywords. In the language reference, constant width shows syntax elements that must be used exactly as shown. For example, the if
keyword, parentheses, and else
keyword must be used exactly as follows:
if (
condition
)
statement
else
statement
A function name that is followed by parentheses refers to a function call, typically to obtain the function result. The function name without the parentheses refers to the function in more general terms. For example:
The empty
function returns true
if the container is empty, e.g., size( ) == 0
.
Constant Width Italic
Used in the language reference chapters for syntax elements that must be replaced by your code. In the previous example, you must supply the condition
and the two statement
s.
Constant Width Bold
Used in examples to highlight key lines, and in complex declarations to highlight the name being declared. In some C++ declarations, especially for templates, the name gets buried in the middle of the declaration and can be hard to spot.