作者: Andrew Koenig / Barbara E. Moo
出版社: Addison-Wesley Professional
出版年: 2000-8-24
页数: 352
定价: USD 49.99
装帧: Paperback
ISBN: 9780201703535
内容简介 · · · · · ·
豆瓣成员常用的标签(共20个) · · · · · ·
喜欢读"Accelerated C++"的人也喜欢 · · · · · ·
按有用程度 按页码先后 最新笔记
-
16.1
Universe (Hello, world.)
16.1 Use the abstractions you have In particular, if we design our own abstractions well, we should be able to use them to solve problems that we had not considered when we designed them. (更多)16.1 Use the abstractions you have
(收起)In particular, if we design our own abstractions well, we should be able to use them to solve problems that we had not considered when we designed them.
2011-08-03 22:20:35 回应
-
15.1
Universe (Hello, world.)
这一张讲的是设计,有人对我说过,写代码不值钱,设计才值钱。不过值钱的东西往往不容易理解,像这章就是。将现实问题分解,然后再重新构成软件,本身就是一个费脑筋的过程。要把这个过程给不了解的人讲清楚,就更费脑筋了。这一章的讲解只能说合格,没有前面的章节那么容易理解。 15.1.1 Using inheritance to model the structure We'll call the derived classes String_Pic, for pictures created from strings that our u... (更多)这一张讲的是设计,有人对我说过,写代码不值钱,设计才值钱。不过值钱的东西往往不容易理解,像这章就是。将现实问题分解,然后再重新构成软件,本身就是一个费脑筋的过程。要把这个过程给不了解的人讲清楚,就更费脑筋了。这一章的讲解只能说合格,没有前面的章节那么容易理解。15.1.1 Using inheritance to model the structureWe'll call the derived classes String_Pic, for pictures created from strings that our user gives us; Frame_Pic, for a picture created by framing another picture; and HCat_Pic and VCat_Pic, for pictures that are the result of concatenating two other pictures horizontally or vertically respectively. By relating these classes through inheritance, we can use virtual functions to write code that doesn't always need to know the precise kind of picture on which it is operating. That way, our users can still use any of our operations without knowing which kind of picture is being manipulated. We will derive each of these classes from a common base class, which we shall call Pic_base, resulting in the following inheritance hierarchy:
String_Pic 创建 strings 形成的图案(picture);Frame_Pic 创建装饰 strings 的框(frame);HCat_Pic 和 VCat_Pic 水平或垂直的组合不同的图案(pictures)。
为了隐藏细节,提供了接口类(interface class),具体实现类不提供 public interface,后面为了实现时能互相调用成员函数(member function),用了友元(friend)。这符合高内聚、低耦合的原则。The next question to resolve is whether to make the inheritance hierarchy visible to our users. There seems to be little reason to do so. None of our operations deals with specific kinds of pictures; instead, they all deal with the abstract notion of a picture. So, there is no need to expose the hierarchy. Moreover, because we intend to use a reference- counting strategy, our users will find it more convenient if we hide the inheritance and associated reference counting. Instead of making our users deal directly with Pic_base and its associated derived classes, we'll define a picture-specific interface class. Our users will access that class, freeing them from having to be aware of any of our implementation's details. In particular, using an interface class will hide the inheritance hierarchy, along with the fact that our class relies on Ptr. Apparently, then we'll need to define six classes: the interface class, the base class for our inheritance hierarchy, and the four derived classes. We'll call the interface class Picture. Internally, Picture will use a Ptr to manage its data.
So far, the Picture class is pretty simple: The only operation is to create a Picture from a vector of strings. We use a default argument (§7.3/127) to make that vector optional. If a user constructs a Picture with no argument, then the compiler will supply vector<string>() as an argument automatically, which yields a vector<string> with no elements. Therefore, the effect of the default argument is to allow us to use a definition such as
Picture p; // an empty Picture
先想做什么,再想怎么做。 (收起)to create a Picture with no rows.
2011-07-31 09:07:20 回应
-
15.2
Universe (Hello, world.)
15.2.3 Padding the output Static members (both functions and static data members, which we can also define) are useful in that they let us minimize the names that are defined globally. Our pad function is a good example. We can imagine many abstractions that have the notion of padding. In this book we talked about padding in the context of writing a formatted report of student grades, as well a... (更多)15.2.3 Padding the output
关于 static function 的用途。Static members (both functions and static data members, which we can also define) are useful in that they let us minimize the names that are defined globally. Our pad function is a good example. We can imagine many abstractions that have the notion of padding. In this book we talked about padding in the context of writing a formatted report of student grades, as well as in the context of writing Pictures. If the Picture class were to define pad as a global function, then we would not also be able to define a pad function for Student_info, or vice versa. By making pad a static member, we allow for the fact that other abstractions in our program might have the notion of padding. As long as each class defines what pad means only in the context of the class, these mutually independent notions of padding can coexist within our program.
Protected members 的访问限制。 (收起)A member of a derived class (such as Frame_Pic) can access the protected members of the base-class parts of objects of its own class (such as Frame_Pic), or of other classes derived from it, but it cannot access the protected members of base-class objects that stand alone—that is, that are not part of a derived-class object. Therefore, member functions of class Frame_Pic, which is derived from class Pic_base, can access protected members of the Pic_base parts of Frame_Pic objects, or objects of classes derived from Frame_Pic, but they cannot access protected members of stand-alone Pic_base objects directly.
2011-07-29 17:21:50 回应
-
第24页
Universe (Hello, world.)
电子版,没有页数,以章节号为准。 2.4 Writing a row The int type is sufficient for rows because the number of rows depends only on the value of pad, which we control. Every C++ implementation is required to allow every int variable to take on values up to at least 32767, which is plenty. Nevertheless, whenever we define a variable that contains the size of a particular data structure, it is a g... (更多)电子版,没有页数,以章节号为准。2.4 Writing a row
相当细致的type选择,用The int type is sufficient for rows because the number of rows depends only on the value of pad, which we control. Every C++ implementation is required to allow every int variable to take on values up to at least 32767, which is plenty. Nevertheless, whenever we define a variable that contains the size of a particular data structure, it is a good habit to use the type that the library defines as being appropriate for that specific purpose.
const std::string::size_type cols = greeting.size() + pad * 2 + 2;
作为例子,详细说明为什么不直接用int,这是很容易被忽略的地方。 (收起)2011-03-30 16:00:35 回应
-
第25页
Universe (Hello, world.)
电子版,没有页数,以章节号为准。 2.5.1 Abbreviating repeated uses of std:: C++ offers a way of saying that a particular name should always be interpreted as coming from a particular namespace. For example, by writing/代码内容已省略/ we can say that we intend to use the name cout to mean std::cout exclusively, and that we do not intend to define anything named ... (更多)电子版,没有页数,以章节号为准。2.5.1 Abbreviating repeated uses of std::C++ offers a way of saying that a particular name should always be interpreted as coming from a particular namespace. For example, by writing
using std::cout;
相当合理的一种用法,我以前还一直不知道,惭愧。we can say that we intend to use the name cout to mean std::cout exclusively, and that we do not intend to define anything named cout ourselves. Once we have done so, we can say cout instead of std::cout.
这种用法可能知道的人多些,但是在Google C++ Style Guide中直接禁止掉了 http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Namespaces#Namespaces 理由是 This pollutes the namespace.个人认为,在只有几个classes的小项目中可以用。中型以上的项目应该遵照Google C++ Style Guide,因为name的数量到达一定程度后,产生 names collide 的概率会非常大。 (收起)Logically enough, such a declaration is called a using-declaration. The name that it mentions behaves similarly to other names. For example, if a using-declaration appears within braces, the name that it defines has its given meaning from where it is defined to the closing brace.
2011-03-30 21:23:52 回应
-
16.1
Universe (Hello, world.)
16.1 Use the abstractions you have In particular, if we design our own abstractions well, we should be able to use them to solve problems that we had not considered when we designed them. (更多)16.1 Use the abstractions you have
(收起)In particular, if we design our own abstractions well, we should be able to use them to solve problems that we had not considered when we designed them.
2011-08-03 22:20:35 回应
-
15.1
Universe (Hello, world.)
这一张讲的是设计,有人对我说过,写代码不值钱,设计才值钱。不过值钱的东西往往不容易理解,像这章就是。将现实问题分解,然后再重新构成软件,本身就是一个费脑筋的过程。要把这个过程给不了解的人讲清楚,就更费脑筋了。这一章的讲解只能说合格,没有前面的章节那么容易理解。 15.1.1 Using inheritance to model the structure We'll call the derived classes String_Pic, for pictures created from strings that our u... (更多)这一张讲的是设计,有人对我说过,写代码不值钱,设计才值钱。不过值钱的东西往往不容易理解,像这章就是。将现实问题分解,然后再重新构成软件,本身就是一个费脑筋的过程。要把这个过程给不了解的人讲清楚,就更费脑筋了。这一章的讲解只能说合格,没有前面的章节那么容易理解。15.1.1 Using inheritance to model the structureWe'll call the derived classes String_Pic, for pictures created from strings that our user gives us; Frame_Pic, for a picture created by framing another picture; and HCat_Pic and VCat_Pic, for pictures that are the result of concatenating two other pictures horizontally or vertically respectively. By relating these classes through inheritance, we can use virtual functions to write code that doesn't always need to know the precise kind of picture on which it is operating. That way, our users can still use any of our operations without knowing which kind of picture is being manipulated. We will derive each of these classes from a common base class, which we shall call Pic_base, resulting in the following inheritance hierarchy:
String_Pic 创建 strings 形成的图案(picture);Frame_Pic 创建装饰 strings 的框(frame);HCat_Pic 和 VCat_Pic 水平或垂直的组合不同的图案(pictures)。
为了隐藏细节,提供了接口类(interface class),具体实现类不提供 public interface,后面为了实现时能互相调用成员函数(member function),用了友元(friend)。这符合高内聚、低耦合的原则。The next question to resolve is whether to make the inheritance hierarchy visible to our users. There seems to be little reason to do so. None of our operations deals with specific kinds of pictures; instead, they all deal with the abstract notion of a picture. So, there is no need to expose the hierarchy. Moreover, because we intend to use a reference- counting strategy, our users will find it more convenient if we hide the inheritance and associated reference counting. Instead of making our users deal directly with Pic_base and its associated derived classes, we'll define a picture-specific interface class. Our users will access that class, freeing them from having to be aware of any of our implementation's details. In particular, using an interface class will hide the inheritance hierarchy, along with the fact that our class relies on Ptr. Apparently, then we'll need to define six classes: the interface class, the base class for our inheritance hierarchy, and the four derived classes. We'll call the interface class Picture. Internally, Picture will use a Ptr to manage its data.
So far, the Picture class is pretty simple: The only operation is to create a Picture from a vector of strings. We use a default argument (§7.3/127) to make that vector optional. If a user constructs a Picture with no argument, then the compiler will supply vector<string>() as an argument automatically, which yields a vector<string> with no elements. Therefore, the effect of the default argument is to allow us to use a definition such as
Picture p; // an empty Picture
先想做什么,再想怎么做。 (收起)to create a Picture with no rows.
2011-07-31 09:07:20 回应
-
15.2
Universe (Hello, world.)
15.2.3 Padding the output Static members (both functions and static data members, which we can also define) are useful in that they let us minimize the names that are defined globally. Our pad function is a good example. We can imagine many abstractions that have the notion of padding. In this book we talked about padding in the context of writing a formatted report of student grades, as well a... (更多)15.2.3 Padding the output
关于 static function 的用途。Static members (both functions and static data members, which we can also define) are useful in that they let us minimize the names that are defined globally. Our pad function is a good example. We can imagine many abstractions that have the notion of padding. In this book we talked about padding in the context of writing a formatted report of student grades, as well as in the context of writing Pictures. If the Picture class were to define pad as a global function, then we would not also be able to define a pad function for Student_info, or vice versa. By making pad a static member, we allow for the fact that other abstractions in our program might have the notion of padding. As long as each class defines what pad means only in the context of the class, these mutually independent notions of padding can coexist within our program.
Protected members 的访问限制。 (收起)A member of a derived class (such as Frame_Pic) can access the protected members of the base-class parts of objects of its own class (such as Frame_Pic), or of other classes derived from it, but it cannot access the protected members of base-class objects that stand alone—that is, that are not part of a derived-class object. Therefore, member functions of class Frame_Pic, which is derived from class Pic_base, can access protected members of the Pic_base parts of Frame_Pic objects, or objects of classes derived from Frame_Pic, but they cannot access protected members of stand-alone Pic_base objects directly.
2011-07-29 17:21:50 回应
书评 · · · · · · (共14条) 我来评论这本书
热门评论 最新评论
标准的C++入门
-
- 五点半(1234567890二次开奖) Koneing两口子真不愧为教育专家。从20多年前的《C陷阱与缺陷》,到《C++沉思录》,再到这本 《Accelerated C++》无不是语言学习的必修之课。特别这本《Accelerated C++》可以说是最佳的C++入门书籍。 Koneing对C++学习有三点建议:尽量避免使用指针;提倡使用程序库;用类表达概念...... (2回应)2007-06-25 22/22有用来自 中国电力出版社2003版
很好很强大
-
- Lovely Vin 我的第一本教程,选它的原因是因为它很不厚,很适合带着到处走,后来认真看了之后发现真的是一本很不错的书,特别是里面的例子很实用(不像其他教科书那样都是要你求两个数的最大公约数之类的问题),并且里面的因为也很易懂,呵呵,推荐像我这样的新手阅读......2008-11-28 6/6有用来自 中国电力出版社2003版
好书!
-
- perl_xsm 这本书,可能是最好的起点之一,当然,绝对不是学习的终点。我在啃了4遍C++ Primer,钻研了几遍effective,more effevtive,作出了一些小的项目之后,回头来看这本书,觉得本书的内容绝对够资格称得上初学者的圣经。本书的译者,靳志伟先生,在翻译过程中,确实是下了一番功夫,在中国能多有一些这样的翻译,...... (2回应)2008-03-22 6/6有用来自 机械工业出版社2007版
Accelerated C++
-
- kevinhan4089 这本书是我的第一本C/C++ 正式学习书籍,之所以说是正式,是因为原来看过谭浩强的C++,以及一本C++简读本的书籍,发现当时浪费了大量时间,如果刚开始就这本加速C++学起来,效果可能会更好,这本书的确写得非常好,作者从初学者角度将例子贯穿与知识点,教学方法非常独特,相比与国内很多只是写一堆理论,然后给几个例子和习题来...... (1回应)2011-12-03 2/2有用来自 机械工业出版社2006版
在林林总总的C++书籍中,入门的书真的不多。
-
- nokivan 由于C++语言的复杂性,在林林总总的C++书籍中,入门的书真的不多。恰好,本书就是属于极易入门的一本书。非常适合初学者阅读。注意,是非常!本书循序渐进,个人强烈推荐! “抱歉,你的评论太短了”。。那就来长点 = =。。。......2012-02-11 来自 中国电力出版社2003版
introduction to c++
-
- studyfang 读完c++ primer,再读完ac++,惊叹于koenig夫妇竟用如此紧凑的篇幅展示c++诱人的魅力,的确是c++很好的入门书籍……正像作者所说,“once you have written enough programs that use the material that we have covered so f......2011-05-22 2/2有用
c++程序员必读书籍
-
- 梦在银河系 作者在C++方面有丰富的使用经验,所以在语言的讲解方面游刃有余。 这本书通过代码(非玩具代码)展现了C++的一些主要的特征,对初学者来说起到了高屋建瓴的作用,对于有C++基础的人来说,也是一种知识和理解的梳理,本书文笔清晰,内容实在,个人打6星。(ps:强烈建议看英文版,我之前看翻译版的,阅读速度还不如看原版的快)......2011-10-15
看完靳志伟的翻译再也不相信爱情了
-
- tk 英文版看过两三章,看的比较慢,后来没想到在图书馆发现了一本机械工业出版社靳志伟翻译的版本,于是非常高兴的借走,结果越看越无语。这本书自然是很好的一本书,但是这本书的中文版。。。看完之后给人的感觉就像是吞了一口苍蝇,恶心至极。 这哪是翻译啊?纯粹是直译,靳老师您直译就直译吧,别把人家的意思给曲解了也行啊,你把人家的......2011-05-18
一本入门用的好书!
-
- ACC 学期初的时候买了这本书,又在图书馆借到了相应的中文版,然后就是拿着英文版的一句一句的啃,遇到不懂的地方在看中文的翻译,就这样,半个学期过去了,已经看完了本书的绝大部分。 现在是学期末了,想起来这本书还差倒数第二章,也就是chapter15没有看,因此多少都觉得有点不完美,没有坚持到最后。 不过最后一章cha......2010-07-08 1/1有用来自 机械工业出版社2006版
"Accelerated C++"的论坛 · · · · · ·
| 看完 & 敲了一遍代码 | 来自olostin | 1 回应 | 2011-12-08 |
| 没看出哪里好 | 来自草头菜 | 2010-07-21 |
在哪儿买这本书? · · · · · ·
- 亚马逊 (RMB 493.10)
- 查看1家网店价格 (493.10元起)
- 加入购书单 多本比价 批量购买 已在购书单
这本书的其他版本 · · · · · · ( 全部4 )
以下豆列推荐 · · · · · · (全部)
- C++ Collections (Alex Vonduar)
- The Definitive C++ Book Guide and List (伊卡洛斯)
- C&CPP (Jovi.Lee)
- 我的。。。 (leo)
- The C++ In-Depth Series (孙大伟)
谁读这本书?
tags:很不错
读了前两章,感觉很容易读懂,例程也很有意思,结合习题来看,这本书非常适合刚入门的C++的学习者。 p.s 简明而不简单,短小精悍,重视实践,是这本书的特色,看完这本书和C++Primer,加上一定的工程经验,可以去试试The C++ Programming Language了。
> 30人在读
> 49人读过
> 46人想读
喜欢这本书的人关注的活动 · · · · · ·
订阅关于Accelerated C++的评论:
feed: rss 2.0












