C++ in a Nutshell


Last updated: June 20, 2008.

Deletions are shown with red strike-through style. Insertions are in blue bold italics. Please send additional errata to cpp @ cpphelp.com.

Thanks to Paul Bailey, Markus Dittrich, Reed Hedges, Tsunehiko Ishitani, James Jennings, Michael Kochetkov, Mark Kvale, Chris Lattner, Eljay Love-Jensen, Matthias Ragaz, Stefan Stoll, and Ranko Veselinovic for finding and reporting errors.

p. 14, paragraph 4, change:

This declaration actually declares a function named data, which takes two parameters. The first is named cin and has of type istream_iterator<int>. The first parameter is named cin, and the second is an unnamed pointer to a function that returns istream_iterator<int>nameless. You can force the compiler to interpret the declaration as an...

p. 25, between 4th and 5th items at the top of the page, insert:

unsigned int

Represents an unsigned integer in a size that is natural for the host environment.

p. 28, line 3 of the typedef example:

typedef double matrix[3][3] matrix;

p. 35, second code block, lines 4, 6, 8:

int & &rr;         (insert a space between & and &)
int *&* rp = &r;
int *&* pr = p;

p. 35, Example 2-12 and the discussion before it are wrong. The reference to const does not eliminate any copying of the structure returned from std::div.

p. 42: last line on page: change:

packages in a single source fileprogram.

p. 45: Example 2-17: insert "ns" in line 5

namespace ns = original;     // Alias

p. 59: last line, append:

depth; each subsection covers a single precedence group. The following descriptions apply only to the built-in operators. You can overload many operators for user-defined types (enumerations and classes). See Chapter 5 for more information.

p. 137, Example 6-3, delete extraneous asterisk:

*char strval[8];

p. 149: 2nd full paragraph:

...object, then the copy constructor is called to copy the temporary object into pz. (The compiler is allowed to optimize away the copy and initialize pz directly. Most...

p. 150: line 3 of first code fragment:

return pz;

p. 196: 1st code snippet, last line, insert:

wrapper<> w;

p. 217: 2nd complete paragraph, change:

"\xe0\x8f\xcf\x80". Many character sets do not have any encoding..."

p. 251:

insert "const": bool empty() const

insert "iterator": erase(iterator first, iterator last)

insert "const": size_type max_size() const

insert "const": size_type size() const

p. 296 (const qualifier) insert in first paragraph:

(line 3) cannot be the target of an assignment, and you cannot call any of its non-const member

(line 7) member function, this is a const pointer to const, and the member function can be called for

p. 298 (declarator) insert quotes around literal square brackets:

direct-declarator ::= declarator-id |
    direct-declarator ( parm-decl-clause ) [cv-qualifier-seq] [exception-specification] |
    direct-declarator "[" [constant-expr] "]" |
    ( declarator )

direct-abstract-declarator ::=
    [direct-abstract-declarator] ( parm-decl-clause ) [cv-qualifier-seq] [exception-specification] |
    [direct-abstract-declarator] "[" [constant-expr] "]" |
    ( abstract-declarator )

p. 330: first paragraph of adjacent_find: move asterisk outside of parentheses:

range [first, last) that are equal (first version) or in which pred(*iter, *(*iter+1)) is

p. 338: Example 13-1: insert "const" for operator bool()

operator bool() const { return sorted; }

p. 356: replace_copy_if: change Iter to InIter

OutIter replace_copy_if(InIter first, InIter last, OutIter result, Predicate pred,
                        const T& new_value);

p. 438: strtoul, end of first paragraph: delete the errant backtick (`):

If the third part is empty, *end` points to the termi-

p. 489: bind2nd function template, line 2, change:

when you have a binary function and always want to supply the same value as the firstsecond

p. 531: ignore(), first bullet item, change:

p. 542 (middle): insert "&"

insert_iterator<Container>& operator++(int)

p. 543 (bottom):

const T* operator->() const
istream_iterator<T,charT,traits,Distance>& operator++()
Returns a pointer to the item that was read most recently from the stream.
istream_iterator<T,charT,traits,Distance>& operator++(int)
Reads the next item from the stream using operator>>. The return value is *this.
istream_iterator<T,charT,traits,Distance> operator++(int)

Reads the next item from the stream using operator>>. The return value is a copy of *this, made prior to reading from the stream..

p. 551, first paragraph after Figure 13-23. Change:

The following member functions of reverse_iterator refer to adapted as the data member that stores the base() iterator. The adapted member is purely a convenience for the function descriptions and is not necessarily part of any real implementation of reverse_iterator.actually named current, and is a protected data member of reverse_iterator. (See what happens if you change the text after the technical editors have done their work.)

p. 551, last paragraph: change:

Saves a copy of the current item (operator*())*this, decrements adapted, and returns the saved itemcopy of *this.

p. 552, second item, change text paragraph:

Saves a copy of the current item (operator*())*this, increments adapted, and returns the saved itemcopy of *this.

p. 672, par. 3, line 3, change max_string to max_size:

length exceeds max_sizetring() throws length_error.

p. 672, last bullet item, change T to Y: