Anda di halaman 1dari 8

C++ Primer Errata

Last modified 10 June 2008

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!

Technical errors corrected in the ninth printing


• Page 221-222: The text should say that like preprocessor directives, the names of
preprocessor macros are unique within a program and may not be used to define
other entities. Additionally, the text should mention that preprocessor names are
defined outside any namespace. In particular, the assert macro is not defined
inside the std namespace. We may not refer to std::assert, and we may not
provide a using declaration for assert.
• Page 290: The call cin.clear(old_state) in the first code fragment on that
page, should be cin.setstate(old_state).
• Page 313: The description of the compound assignment operators in Table 9.4
incorrectly refer to iter2 as the right-hand operand; in each instance, iter2
should be replaced by n. The right-hand operand must be an integral value, not an
iterator.
• Page 442: In the second code fragment, the call to display should pass cout as
an argument.
• Pages 617-618: The constructors for classes derived from Query_base that take a
Query parameter should be defined to take a const reference to Query.
• Pages 837: In Table A.5 the description of ignore is incorrect. The text in that
table should say "Reads and ignores at most size characters up to and including
delim."

Clarifications made in the ninth printing


• Page 204: The first sentence in Section 6.6.5 was unduly restrictive: As shown
later in that section, we can define variables after any case label, so long as we do
so inside a block.
• Page 220: At the very beginning of the text on that page, "define" should be
"create objects of" to make it clear that we are referring to creating objects of an
exception type.
• Page 239: The comment in the description of the for loop inside the
printValues function should indicate that the array has "at least" 10 elements.
This change makes is clearer that the array might have more than 10 elements, but
is in error if there are fewer than 10 elements.
• Pages 311-312: The introduction to Section 9.2 and Table 9.3 should make it clear
that the operations being discussed apply to the iterators associated with the
standard library containers. Chapter 11 will discuss other kinds of iterators, some
of which do not support all the operations described in this section.
• Pages 314: The third paragraph should indicate that the notation [ first,
last ) is borrowed from mathematics.
• Page 433: The ADVICE section should note the existence of abstract base
classes, indicating that such types are a particularly extreme example of an
abstract data type. Section 15.6 will describe abstract base classes.
• Page 476: The third paragraph should be more precise: Rather than saying that
"the compiler automatically executes" the text should say that "the compiler
automatically generates code to execute."
• Page 517: The first paragraph on this page should make it clear that the object that
is being read into is the one to which the paragraph refers.
• Pages 538-539: The text should make it clear that we are talking about class type
conversions implicitly invoked by the compiler. When we explicitly call a
conversion operator or a constructor, we may use as many as are necessary.
• Page 544: The CAUTION section used an awkward example for one of the
hypothetical conversions from a Date class to int. That discussion has been
revised to suggest a more useful conversion to year, month, and day as the first
possible result.

Typographical errors corrected in the ninth printing


• Page xix: In last word of last sentence of paragraph 2 "possiblities" should be
"possibilities."
• Page xx: The second sentence in the the last full paragraph on the page has an
extra "the" in it.
• Page 2: The word "to" should be added to the last sentence in the first paragraph:
"supply a program to do."
• Page 23: In the KEY CONCEPT section "peeform" should be "perform."
• Page 30: The glossary entry for the != operator should say "Inequality operator."
not "Assignment operator."
• Page 92: In the Value Initialization section fvec should be defined as
vector<int>, not as vector<string>. Also, change the name fvec to ivec to
indicate that the vector holds ints.
• Page 150: The first comment in the code example in the CAUTION section
should say 16 bits not 8 bits.
• Page 155: In the example at the bottom of the page the initializer for bits should
be 0233, not 1.
• Page 182: The code fragment in the section Conversions and Enumeration
Types should refer to point2w not pt2w:

int chunk_size = array_size * point2w;

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:

void printValues(int (*matrix)[10], int rowSize);

not:

void printValues(int (matrix*)[10], int rowSize);

• 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:

ConstRef::ConstRef(int ii): i(ii), ci(ii), ri(i) { }

• 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 &#124&#124 not &#124.
• 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:

(--p)->~T(); // call the destructor

not:

p->~T(); // call the destructor

• 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:

int calc(int&, int&);

not values:

int calc(int, int);

• 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:

class Derived : public Base { ... };

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:

void print(ostream &os) { print(os); os << " " << mem; }

not
void print() { print(ostream &os); os << " " << mem; }

Also, in Exercise 15.9, the initializations of bp1 and bp2 are incorrect. They
should be:

base *bp1 = &bobj; base *bp2 = &dobj;

not

base *bp1 = &base; base *bp2 = &doboj;

• 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.

Technical errors fixed in the third printing


• Page 221: The compiler command line option to define NDEBUG needs a space; the
text should read $CC -D NDEBUG not $CC -DNDEBUG.
• Page 827: The variable bool_val should be initialized before it is printed. The
description of the program is also changed to make it clearer that the stream is
reset.

Clarifications in the third printing


• Pages 217-218: The terminology used when describing try blocks was reworked
to make it clear that the term try block refers not only to the code following the
try but to the associated catch clauses as well.

Anda mungkin juga menyukai