Every book has bugs in it, and C++ Primer is no exception. This page presents all the
bugs that have come to our attention. All of these errors are corrected in the Ninth
printing, July 2008. Many thanks to the careful readers who notified us of these
problems!
not:
int chunk_size = array_size * pt2w;
• Page 204: In the sentence just before section 6.6.5, the word case in "two case
labels" is in the wrong font.
• Page 221: In the sentence near the bottom of the page that begins "As long as
NDEBUG" "condtion" should be "condition"
• Page 231: The code at the bottom of the page should call gcd not rgcd.
• Page 235: In the last paragraph "obvisous" should be "obvious."
• Page 241: The first code fragment in Passing a Multidimensioned Array is
incorrect. It should read:
not:
• Page 261: The paragraph describing the same_isbn function should refer to
this->isbn not this->units_sold and this->revenue.
• Page 267: The second sentence in the last paragraph before the ADVICE section
should be "different from one" not "different from on."
• Page 278: The comment in the code at the top of the page should refer to pf not
pf1.
• Page 300: The word "to" in the third comment in the code fragment should be
dropped.
• Page 307: In the paragraph just ahead of the Note box, the word "speicfied"
should be "specified."
• Page 323: In the Note box at the top of the page the word "is" should be inserted
between "operator" and "defined." The text in this box was also revised slightly to
make it clearer.
• Page 339: The second to last sentence in the paragraph prior to section 9.6.2
should say "not the requested eight."
• Page 344: The last sentence before Table 9.20 should refer to pos1 not pos2.
• Page 391: The first occurrence of the word "generic" is in the wrong font. It
should be "generic."
• Page 402: Near the bottom of page, the boldface predicates should be predicate.
• Page 410: The first heading should be Using ostream_iterators and
istream_iterators.
• Page 432: In the fourth paragraph in section 12.1.2, the word "representated"
should be "represented."
• Page 455: The constructor initializers in the constructor definition at the bottom of
the page should be:
• Page 493: The sentence after the second code fragment should say: "After the
copy, the pointers in ptr1 and ptr2."
• Page 502: The definition of copy control should read "happens when objects" not
"happens when object."
• Page 517: Near the end of the third paragraph "all all" should be "all."
• Page 534: In Table 14.3 the operator symbol associated with the logical_or
should be || not |.
• Page 538: In the comment on the last code example opeator<<. should be
operator<<.
• Page 540: The final paragraph should say that "a standard conversion is applied to
convert sobj from type short."
• Page 546: The header Explicit Constructor Call to Disambiguate should be
Using a Cast to Disambiguate.
• Page 566: Near the end of the first section, "konw" should be "know."
• Page 572: In the code fragment at the bottom of the page struct Derived_from
Private is missing an underscore. It should be struct Derived_from_Private.
• Page 636: The third sentence in the first paragraph, "generatng" should be
"generating."
• Page 640: In two places in the first paragraph following the second code fragment
should refer to the argument d not dd.
• Page 642: At the end of the second sentence in the second paragraph "differnt"
should be "different."
• Page 654: The comments in the first code fragment should refer to
Queue<string> not Queue<int>.
• Page 666: Just before the second code fragment, "inidicate" should be "indicate."
• Page 683: In the definition of function template: "template one or more
parameters" should be "one or more template parameters"
• Page 689: In the paragraph in the middle of the page, "autmatically" should be
"automatically."
• Page 712: The sentence following the code example in Section 17.2.1 should say
that cplusplus_primer defines "four members: three classes and an overloaded
+ operator."
• Page 748: In the last sentence of second to last paragraph in the Chapter
Summary "possiblities" should be "possibilities."
• Pages 763: The second for loop incorrectly ommitted the decrement on the
pointer p. It should read:
not:
• Page 783: In the last sentence on the page the second operator symbol should be
->* not .->.
• Page 793: The TokenValue union is incorrectly described as containing a "pointer
to char." It does not.
• Page 826: In the middle of the page, "placment" should be "placement."
Changes in exercises made in the ninth printing
• Page 43: In Exercise 2.8 the examples should not have begun with a minus sign.
A plus or minus sign may appear as part of a literal constant only in the exponent
of a floating point number. Strictly speaking, as we shall see in Chapter 5, the
examples originally presented were expressions, not literal constants.
• Page 81: Exercise 3.3 should read "Name three ways" not "Name the three ways."
There are in fact many ways to initialize a string, of which we have seen four at
this point in the text.
• Page 210: Exercise 6.16 should read "determine whether one vector is a prefix"
not "determine whether one vectors is a prefix"
• Page 213: Exercise 6.19 is overly constrained. It should note that most (not all) of
the work can be done in the while condition. The loop body is needed to
increment the iterator and the condition should find the element. Also, Exercise
6.20 add the word "the" before "standard input."
• Page 232: Exercise 7.5 should read ask for the larger of "the int value and the
value" not "the int value of the value."
• Page 244: Exercise 7.15 is rewritten to indicate that the arguments passed to main
should be concatenated rather than summed. This change allows the arguments to
be treated as strings not ints.
• Page 270: Exercise 7.34 replace "Define" by "Declare."
• Page 276: The parameters in the first declaration in Exercise 7.39 part (a) should
be references:
not values:
• Page 315: Exercise 9.13 is corrected to make it clear that the program must do
something sensible in the case that the value sought is not found.
• Page 333: In exercise 9.30 the word "stragegy" should be "strategy."
• Page 333: Exercise 9.32 includes code that exists for illustration purposes only
and is not an example of good style. The text has been updated to make it clear
that this code is contrived.
• Page 347: Exercise 9.38 was updated to indicate that it is okay to assume that the
string contains only alphabetic or numeric characters.
• Page 349: Exercise 9.40 is rewritten to make it clear that the strings q1 and q2
are to be used to create the desired output string.
• Page 359: Exercise 10.4 "Give illustrations on" is replaced by "Give an example
of when each of"
• Page 407: Exercise 11.15 should ask the reader to copy the unique elements from
a vector into a list. The exercise incorrectly asks that the copy be made from a
list into a vector. The program for this exercise must sort the container from
which it does the copy. However, the generic sort algorithm does not work with
list. We will see in Section 11.5 that the list type defines its own version of
sort.
• Page 412: Exercise 11.16 should read "on the top of page 410" not "on 410."
• Page 438: In Exercise 12.10, the access labels in the Record class are misplaced.
The constructors, member functions, and typedef should be public. Only the data
members should be private.
• Page 457: Exercise 12.21 "for class" should be "for a class."
• Page 463: The definition of null_isbn in Exercise 12.29 should use direct-
initialization (using parentheses) rather than copy-initialization (using the =
symbol). It is not until the next chapter, Chapter 13, that we cover how copy-
initialization works for class types.
• Page 470: The last sentence in Exercise 12.40 should refer to FooVal, not xval.
• Page 472: Exercise 12.41 should ask the reader to initialize the static members of
Bar not Foo.
• Page 510: Exercise 14.4 drop the definitions of svec1 and svec2 to avoid the
appearance that we are fetching elements from empty vectors.
• Page 521: Exercise 14.14 add the words "a string representing an" in front of
ISBN to make it clear that the operator should take a string not an object of type
isbn.
• Page 536: Exercise 14.37 should read "define an expression" not "define an
object."
• Page 536: Exercise 14.39 requires the use of library function objects that are
beyond the scope of this book. It is replaced by: "Use library function objects to
determine whether a given int value is divisible by any element in a
vector<int>."
• Page 540: The conversion functions in Exercise 14.41 incorrectly omitted the
operator keyword.
• Page 548: The class definitions in Exercises 14.44 and 14.45 contain errors:
Exercise 14.44, LongDouble needs a public access label to make the conversion
operators accessible and Exercise 14.45 needs a colon following the public label.
• Page 551: Exercise 14.46 replace "operation in main" by "expression used to
initialize res." Also, the argument to the LongDouble addition operator should be
Complex not complex.
• Page 567: Change Exercise 15.5 (b) to:
The exericse as originally written required the reader to understand that the
access_label is optional. However, this fact is not covered until Section 15.2.5.
• Page 571: In Exercise 15.8, the print function in class derived is incorrect. It
should be:
not
void print() { print(ostream &os); os << " " << mem; }
Also, in Exercise 15.9, the initializations of bp1 and bp2 are incorrect. They
should be:
not
• Page 577: Exercise 15.13 is overly complicated. There is no need to define both
classes C1 and C2, because they are identical.
• Page 591: Exercise 15.22 is rewritten to clarify which classes the reader should
rewrite: The classes to reimplement are the one defined for Exercise 15.7 and the
Bulk_item class.
• Page 592: The classes defined for Exercise 15.23 had three errors: The foo
functions in both classes incorrectly failed to name a return type and the function
named bar incorrectly reused the name of a data member of its class. The fixes
are to make both foo members return void and to rename the bar function of
class Derived as bar_fcn.
• Page 628: Exercise 16.6 drop the word "a" in "our a simplified." Also changed
"queue" to "the standard queue class."
• Page 641: Exercise 16.22 the declaration of fcn incorrectly omitted the close
parentheses on the parameter list. Also, the example calls are incorrect: Parts (a)
and (b) should call fcn, and part (c) should call calc.
• Page 669: Exercise 16.47 should end with a question mark not a period.
• Page 674: In the exercises on this page, the references to count should be to
Count. Also, the last vector mentioned in Exercise 16.53 should be "vector of
strings" not "vector of chars." In Exercise 16.54 the specialized version should
be written to handle vector of const char*, not vector of strings.
• Page 682: There is an extraneous close curly in Exercise 16.63.
• Page 707: Exercise 17.9 ps is an auto_ptr<string> not a "pointer to string."
• Page 740: Exercises 17.31 and 17.32 should note that the member functions
defined in those exercises must be added to the hierarchy on page 739.
• Page 744: The member functions in Exercise 17.33 incorrectly failed to define a
return type.
• Page 787: Exercises 18.28 and 18.29 incorrectly refer to a member named end;
they should instead refer to down.