C++ Common Knowledge: Errata

I'm always interested to hear of any errors or typos in the book.  Before sending a report or comment, please check the list of known errors and typos below to make sure that it has not been previously reported.  If it doesn't already appear, then I'd appreciate your reporting it to commonknowledge@semantics.org.

Errata for the first printing:


mc, 4/15/05
Item 18, p. 63
Both the declaration and definition of  the overloaded function call operator in Fib should include an argument list, as int operator ()().

cw, 7/12/05
Item 18, p. 63
The function object fib is called twice without an intervening sequence point, resulting in undefined behavior.  A simple fix is to put each call to fib in a separate statement.

mc, 4/23/05
Item 18, p. 65
In the declaration of numsteps in the implementation of the integrate function, the variable name should be numSteps.

scd, 3/29/05
Item 19, p. 69
In the constructor for the PlayMusic class, the initializer for song_ should be songFile.

scd, 3/29/05
Item 19, p. 70
In the call to setAction, the auto_ptr  song should use its get member function to provide the conversion to setAction's const Action * formal argument.  Alternatively, the setAction member of Action could be rewritten to use an auto_ptr formal argument.

sdm, 3/27/05
Item 20, p. 72-74
Inexcusably, I used the keyword union as a variable name (an array of 50 States).  The fix is to call the array something that is not a keyword, like states.

bww, 4/27/05
Item 44, p. 151
The half-open interval used to initialize lst should include the fourth element of the a array: std::list<int> lst( a, a+4 ).

scd, 3/29/05
Item 60, p. 223, 224
The keyword union as a variable name.  The fix is to change the name to something that is not a keyword, like states.

fs, 7/18/05
Item 60, p. 223, 224
In the last code fragment the array (a) is changed to iterators (b, e) but the if and swap statement still use the array (a[i], a[j] ) instead of the iterators (*j, *i ).  The implementations of slowsort should read as follows:
template <typename For, typename Comp>
void slowSort(For b, For e, Comp less) {
for(For i( b ); i != e; ++I)
for(For j( i ); j != e ; ++j)
if( less( *j, *i ) )
std::swap( *j, *i );

template <typename For>
void slowSort(For b, For e) {
for(For i( b ); i != e; ++i)
for(For j( i ); j != e ; ++j)
if( *j < *i )
std::swap( *j, *i );


ww, 5/1/05
Item 19, p. 69
The PlayMusic class should contain an ellipsis comment to indicate that the implementation of the inherited pure virtual clone function is overridden.  Alternatively a declaration of "PlayMusic *clone() const;" should appear.

lz, 4/29/05
Item 33, p. 114
"(Note that this implicit call ... is always a non-vitual call.)"  "vitual" should be "virtual."

lz, 4/29/05
Item 40, p. 139
"...declared as a local member of a function..." should be "...declared as a local variable of a function..."


bww, 4/27/05
Item 17, p. 61
"The same problem obtains with..." should probably read "The same problem occurs with...".
This is an example of the "unusual diction" mentioned on page xviii that I was permitted to retain after spirited discussion with the production professionals at AW.  I'm fond of words in general, and try to do what I can to resurrect useful alternative meanings of  common words.  It could well be, however, that this use of "obtain" has run its course, and should be replaced; the idea is to be precise, after all, not to confuse.  Since "obtain" comes (indirectly) from the Latin ob + tenere (to hold), I'll suggest the phrasing "The same problem holds with..."

Eagle-Eyed Contributors

bww = Bradley White
cw = Conrad Weisert
fs = Franz Schnyder

lz = Leor Zolman
mc = Mike Chirico
scd = Steve Dewhurst, the embarrassed author

sdm = Scott Meyers
ww = Attila Feher

Copyright © 2003 by Stephen C. Dewhurst