没有合适的资源?快使用搜索试试~ 我知道了~
首页C++编程大师之作:Thinking in C++ 2nd Edition
C++编程大师之作:Thinking in C++ 2nd Edition
需积分: 10 0 下载量 170 浏览量
更新于2024-07-29
1
收藏 2.29MB PDF 举报
"C++原版书籍,由C++之父编写的英文版,适合学习和查阅,内容涵盖C++标准库及高级主题。"
《Thinking in C++》是C++编程语言的一本经典著作,作者Bruce Eckel是C++领域的权威人物。这本书分为两卷,其中第二卷主要讨论C++的高级特性以及标准库的使用,是深入理解C++的重要参考资料。书中涵盖了1999年更新的C++标准,因此包含了当时最新的语言特性和库支持。
此书的内容包括但不限于:
1. C++基础:深入解释了C++的基础语法,如类、对象、继承、多态等面向对象编程的核心概念。
2. 标准库介绍:详细介绍了C++标准库中的容器(如vector、list、map等)、迭代器、算法、函数对象等,这些都是C++编程中不可或缺的部分。
3. 模板:讨论了C++的模板机制,包括函数模板、类模板和模板元编程,这些是实现泛型编程的关键工具。
4. 异常处理:阐述了如何在C++中有效地使用异常来处理程序运行时的错误。
5. 输入/输出流(iostream):详尽讲解了iostream库,包括流的使用、流buf和流操作符,对于读写文件和控制台交互至关重要。
6. 高级话题:涵盖了C++的一些复杂特性,如命名空间、内联函数、运算符重载、动态内存管理、预处理器宏等。
7. 编程实践:提供了许多实际编程技巧和最佳实践,帮助读者将理论知识应用于实际项目中。
此外,书中还强调了C++的面向对象设计原则,如单一职责原则、开闭原则等,并通过丰富的实例来展示如何有效地使用这些原则。作者鼓励读者通过实践来深化理解,因此书中包含了大量的示例代码和练习题。
为了保持对C++最新发展动态的关注,作者还提到了他的免费通讯服务,读者可以通过订阅获取关于对象导向编程的最新信息、书籍、研讨会和CD等相关资源。
《Thinking in C++》是一本深度和广度兼备的C++教程,无论是初学者还是有经验的程序员,都可以从中获益匪浅。通过阅读这本书,读者可以系统地学习C++语言,掌握其核心概念和高级特性,提升自己的编程技能。

Preface 15
and other “sophisticated” concepts, scuttling away in shame when the subjects came up in
conversation rather than reaching out for new knowledge.
When I began my struggle to understand C++, the only decent book was Stroustrup’s self-
professed “expert’s guide,
1
” so I was left to simplify the basic concepts on my own. This
resulted in my first C++ book,
2
which was essentially a brain dump of my experience. That
was designed as a reader’s guide, to bring programmers into C and C++ at the same time.
Both editions
3
of the book garnered an enthusiastic response.
At about the same time that
Using C++
came out, I began teaching the language in live
seminars and presentations. Teaching C++ (and later, Java) became my profession; I’ve seen
nodding heads, blank faces, and puzzled expressions in audiences all over the world since
1989. As I began giving in-house training with smaller groups of people, I discovered
something during the exercises. Even those people who were smiling and nodding were
confused about many issues. I found out, by creating and chairing the C++ and Java tracks at
the Software Development Conference for many years, that I and other speakers tended to
give the typical audience too many topics, too fast. So eventually, through both variety in the
audience level and the way that I presented the material, I would end up losing some portion
of the audience. Maybe it’s asking too much, but because I am one of those people resistant to
traditional lecturing (and for most people, I believe, such resistance results from boredom), I
wanted to try to keep everyone up to speed.
For a time, I was creating a number of different presentations in fairly short order. Thus, I
ended up learning by experiment and iteration (a technique that also works well in C++
program design). Eventually I developed a course using everything I had learned from my
teaching experience. It tackles the learning problem in discrete, easy-to-digest steps and for a
hands-on seminar (the ideal learning situation), there are exercises following each of the
presentations.
The first edition of this book developed over the course of two
years, and the material in this
book has been road-tested in many forms in many different seminars. The feedback that I’ve
gotten from each seminar has helped me change and refocus the material until I feel it works
well as a teaching medium. But it isn’t just a seminar handout – I tried to pack as much
information as I could within these pages, and structure it to draw you through, onto the next
subject. More than anything, the book is designed to serve the solitary reader, struggling with
a new programming language.
1
Bjarne Stroustrup,
The C++ Programming Language
, Addison-Wesley, 1986 (first edition).
2
Using C++
,
Osborne/McGraw-Hill 1989.
3
Using C++
and
C++ Inside & Out
,
Osborne/McGraw-Hill 1993.

Preface 16
Goals
My goals in this book are to:
1.
Present the material a simple step at a time, so the reader can easily digest
each concept before moving on.
2.
Use examples that are as simple and short as possible. This sometimes
prevents me from tackling “real-world” problems, but I’ve found that
beginners are usually happier when they can understand every detail of an
example rather than being impressed by the scope of the problem it solves.
Also, there’s a severe limit to the amount of code that can be absorbed in a
classroom situation. For this I sometimes receive criticism for using “toy
examples,” but I’m willing to accept that in favor of producing something
pedagogically useful.
3.
Carefully sequence the presentation of features so that you aren’t seeing
something you haven’t been exposed to. Of course, this isn’t always
possible; in those situations, a brief introductory description will be given.
4.
Give you what I think is important for you to understand about the
language, rather than everything I know. I believe there is an “information
importance hierarchy,” and there are some facts that 95% of programmers
will never need to know, but that would just confuse people and add to their
perception of the complexity of the language. To take an example from C, if
you memorize the operator precedence table (I never did) you can write
clever code. But if
you
have to think about it, it will confuse the
reader/maintainer of that code. So forget about precedence, and use
parentheses when things aren’t clear. This same attitude will be taken with
some information in the C++ language, which I think is more important for
compiler writers than for programmers.
5.
Keep each section focused enough so the lecture time – and the time
between exercise periods – is small. Not only does this keep the audience’
minds more active and involved during a hands-on seminar, but it gives the
reader a greater sense of accomplishment.
6.
Provide the reader with a solid foundation so they can understand the issues
well enough to move on to more difficult coursework and books (in
particular, Volume 2 of this book).
7.
I’ve endeavored not to use any particular vendor’s version of C++ because,
for learning the language, I don’t feel like the details of a particular

Preface 17
implementation are as important as the language itself. Most vendors’
documentation concerning their own implementation specifics is adequate.
Chapters
C++ is a language where new and different features are built on top of an existing syntax.
(Because of this it is referred to as a
hybrid
object-oriented programming language.) As more
people have passed through the learning curve, we’ve begun to get a feel for the way
programmers move through the stages of the C++ language features. Because it appears to be
the natural progression of the procedurally-trained mind, I decided to understand and follow
this same path, and accelerate the process by posing and answering the questions that came to
me as I learned the language and that came from audiences as I taught it.
This course was designed with one thing in mind: to streamline the process of learning the
C++ language. Audience feedback helped me understand which parts were difficult and
needed extra illumination. In the areas where I got ambitious and included too many features
all at once, I came to know – through the process of presenting the material – that if you
include a lot of new features, you have to explain them all, and the student’s confusion is
easily compounded. As a result, I’ve taken a great deal of trouble to introduce the features as
few at a time as possible; ideally, only one major concept at a time per chapter.
The goal, then, is for each chapter to teach a single concept, or a small group of associated
concepts, in such a way that no additional features are relied upon. That way you can digest
each piece in the context of your current knowledge before moving on. To accomplish this, I
leave some C features in place for longer than I would prefer. The benefit is that you will not
be confused by seeing all the C++ features used before they are explained, so your
introduction to the language will be gentle and will mirror the way you will assimilate the
features if left to your own devices.
Here is a brief description of the chapters contained in this book:
(5) Introduction to iostreams
. One of the original C++ libraries – the one that provides the
essential I/O facility – is called iostreams. Iostreams is intended to replace C’s
stdio.h
with an
I/O library that is easier to use, more flexible, and extensible – you can adapt it to work with
your new classes. This chapter teaches you the ins and outs of how to make the best use of the
existing iostream library for standard I/O, file I/O, and in-memory formatting.
(15) Multiple inheritance
. This sounds simple at first: A new class is inherited from more
than one existing class. However, you can end up with ambiguities and multiple copies of
base-class objects. That problem is solved with virtual base classes, but the bigger issue
remains: When do you use it? Multiple inheritance is only essential when you need to
manipulate an object through more than one common base class. This chapter explains the
syntax for multiple inheritance, and shows alternative approaches – in particular, how
templates solve one common problem. The use of multiple inheritance to repair a “damaged”
class interface is demonstrated as a genuinely valuable use of this feature.

Preface 18
(16) Exception handling
. Error handling has always been a problem in programming. Even if
you dutifully return error information or set a flag, the function caller may simply ignore it.
Exception handling is a primary feature in C++ that solves this problem by allowing you to
“throw” an object out of your function when a critical error happens. You throw different
types of objects for different errors, and the function caller “catches” these objects in separate
error handling routines. If you throw an exception, it cannot be ignored, so you can guarantee
that
something
will happen in response to your error.
(17) Run-time type identification
.
Run-time type identification (RTTI) lets you find the
exact type of an object when you only have a pointer or reference to the base type. Normally,
you’ll want to intentionally ignore the exact type of an object and let the virtual function
mechanism implement the correct behavior for that type. But occasionally it is very helpful to
know the exact type of an object for which you only have a base pointer; often this
information allows you to perform a special-case operation more efficiently. This chapter
explains what RTTI is for and how to use it.
Exercises
I’ve discovered that simple exercises are exceptionally useful during a seminar to complete a
student’s understanding, so you’ll find a set at the end of each chapter.
These are fairly simple, so they can be finished in a reasonable amount of time in a classroom
situation while the instructor observes, making sure all the students are absorbing the material.
Some exercises are a bit more challenging to keep advanced students entertained. They’re all
designed to be solved in a short time and are only there to test and polish your knowledge
rather than present major challenges (presumably, you’ll find those on your own – or more
likely they’ll find you).
Exercise solutions
Solutions to exercises can be found in the electronic document
The C++ Annotated Solution
Guide
, Volume 2 by Chuck Allison, available for a small fee from www.BruceEckel.com. [[
Note this is not yet available ]]
Source code
The source code for this book is copyrighted freeware, distributed via the web site
http://www.BruceEckel.com. The copyright prevents you from republishing the code in print
media without permission.
Although the code is available in a zipped file on the above web site, you can also unpack the
code yourself by downloading the text version of the book and running the program
ExtractCode
(from Volume 2 of this book), the source for which is also provided on the Web

Preface 19
site. The program will create a directory for each chapter and unpack the code into those
directories. In the starting directory where you unpacked the code you will find the following
copyright notice:
//:! :CopyRight.txt
Copyright (c) Bruce Eckel, 1999
Source code file from the book "Thinking in C++"
All rights reserved EXCEPT as allowed by the
following statements: You can freely use this file
for your own work (personal or commercial),
including modifications and distribution in
executable form only. Permission is granted to use
this file in classroom situations, including its
use in presentation materials, as long as the book
"Thinking in C++" is cited as the source.
Except in classroom situations, you cannot copy
and distribute this code; instead, the sole
distribution point is http://www.BruceEckel.com
(and official mirror sites) where it is
freely available. You cannot remove this
copyright and notice. You cannot distribute
modified versions of the source code in this
package. You cannot use this file in printed
media without the express permission of the
author. Bruce Eckel makes no representation about
the suitability of this software for any purpose.
It is provided "as is" without express or implied
warranty of any kind, including any implied
warranty of merchantability, fitness for a
particular purpose or non-infringement. The entire
risk as to the quality and performance of the
software is with you. Bruce Eckel and the
publisher shall not be liable for any damages
suffered by you or any third party as a result of
using or distributing software. In no event will
Bruce Eckel or the publisher be liable for any
lost revenue, profit, or data, or for direct,
indirect, special, consequential, incidental, or
punitive damages, however caused and regardless of
the theory of liability, arising out of the use of
or inability to use software, even if Bruce Eckel
and the publisher have been advised of the
possibility of such damages. Should the software
prove defective, you assume the cost of all
剩余592页未读,继续阅读

sjmp
- 粉丝: 56
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

最新资源
- 免注册的SecureCRT中文版压缩文件解压使用
- FB2Library:.NET跨平台库解读FB2电子书格式
- 动态规划在购物优化中的应用研究
- React圆形进度按钮组件的设计与实现
- 深入了解航班订票系统的Java Web技术实现
- ASP.NET下谷歌地图控件的应用与开发示例
- 超好用的电影压缩包文件解压缩指南
- R2D3机器人仿真项目:面向教育研究的免费开发环境
- 安川HP20D机器人模型优化设计流程
- 数字信号处理与仿真程序的现代应用
- VB数据库操作初学者入门示例教程
- iOS音乐符号库MusicNotation:渲染乐谱与高度定制
- Ruby开发者的Unicode字符串调试助手
- ASP.NET网上商店代码实现与应用指南
- BMPlayer:iOS端多功能视频播放器开发解析
- 迅雷资源助手5.1:P2P搜索功能全面升级
安全验证
文档复制为VIP权益,开通VIP直接复制
