C++ Primer 中文版(第4版) 不完全勘误表

来源:互联网 发布:新网域名不加www 编辑:程序博客网 时间:2024/04/20 03:47


勘误人:  celeil 时间:  2006-05-07 10:27:00
页码:  6 行:  -6~-5
错误:  将会导致程序错误推断崩溃位置。 更正:  将会导致错误推断程序的崩溃位置。
附言:  原文:Forgetting to do so may cause output to be left in the buffer if the program crashes, leading to incorrect inferences about where the program crashed.
显然是警告程序员诊断程序时这样做容易搞错程序出错的位置,而不是程序自己推断错位置。

勘误人:  zngy78 时间:  2006-04-14 13:08:04
页码:  32 行:  1
错误:  plain char 更正:  普通char
附言:  不存在plain char关键字,应区别出plain

勘误人:  celeil 时间:  2006-05-18 09:37:10
页码:  56        行:  +6
错误:  但可以重定义在类外的名字 更正:  但这些被定义的名字可以在类外重定义。(我的翻译:但这些名字却可以在这个类以外被重新定义和使用)
附言:  Each class defines its own scope (Section 2.3.6, p. 54). That is, the names given to the data and operations inside the class body must be unique within the class but can reuse names defined outside the class.
这里的"names defined"显然是指"names defined inside the class"。这本书总在这些关键处出错,译书的看不懂英文,难道还不懂C++吗?什么叫“可以重定义在类外的名字”,“类外”太广泛了。

勘误人:  YYQQTT 时间:  2006-05-24 21:32:26
页码:  80 行:  +13
错误:  vector<string> fvec(10);       更正:  vector<int> fvec(10);

勘误人:  shenjianyong 时间:  2006-05-23 08:51:26
页码:  83 行:  +9
错误:  cout<<ivec[10]; 更正:  cout<<ivec2[10];
附言:  上一行定义的为ivec2

勘误人: 王忠瑞时间: 2006-06-24 10:14:58页码: 137行: +21错误: 第二个cout语句解释为:(cout<< 10) < 42更正: 第三个cout语句解释为:(cout<< 10) < 42附言: 虽然原文此处也为
The second cout is interpreted as
(cout << 10) < 42;
但显然第二个cout语句(cout << (10 < 42))是不会被解释成:(cout<< 10) < 42的,此处原文笔误,但译者没有发现。
请指教。

勘误人:  zngy78 时间:  2006-04-14 13:16:58
页码:  179 行:  -2
错误:  ...则始终不执行statement。 更正:  ...则始终不执行expression。
附言:虽然原文是:If condition evaluates to false on the first iteration, expression is never executed.但我却认为这里应是statement而不是expression(原文错误),毕竟statement才是for循环的主体,而且如果statement不被执行当然下一次循环初进行的expression当然也不会被执行了。

勘误人:  zngy78 时间:  2006-04-14 13:16:13
页码:  159 行:  6
错误:  例如,假设有函数string_copy,只有唯一的参数,为char*类型,我们对该函数只读不写。 更正:  例如,假设有函数string_copy,我们对其唯一的char*类型的参数只读不写。
附言:   For example, we might have a function named string_copy that we are certain reads, but does not write, its single parameter of type char*.

页码:  276; 行: 本页下面的例子程序。
错误:  对照原文发现,英文原著里也是错的。细节如下:

作者说如下代码:

vector<int>::iterator first = v.begin(),
                           last = v.end(); // cache end iterator
     // diaster: behavior of this loop is undefined
     while (first != last) {
         // do some processing
         // insert new value and reassign first, which otherwise would be invalid
         first = v.insert(first, 42);
         ++first;  // advance first just past the element we added
在容器变化后end()指向的迭代器就会失效。而基于这个迭代器的循环就会变成死循环。这个观点没有问题。

本书的下面给出解决方案,代码如下:

// safer: recalculate end on each trip whenever the loop adds/erases elements
     while (first != v.end()) {
         // do some processing
         first = v.insert(first, 42); // insert new value
         ++first; // advance first just past the element we added
实际上,它只改正了“end()”方面的错误,但它还是一个死循环。因为循环本身就是错的。
附言:insert操作会在指定位置插入一个对象,那么first = v.insert(first, 42); 在容器最前面插入对象“42”,而把插入的新对象位置再赋给first,接下来++first;指向下一个对象(其实就是插入前的那个对象的位置),然后再做插入操作,再把新插入的对象赋给first……这个循环的效果就是迭代器first始终在容器的第一个对象和新插入的对象间移动——它就永远都满足循环的条件first != v.end(),也就是说它还是一个死循环。

原创粉丝点击