1.1 The Structure of This Book

1.1 The Structure of This Book [notes.intro]
This book consists of six parts:
Introduction: Chapters 1 through 3 give an overview of the C++ language, the key programming
styles it supports, and the C++ standard library.
Part I: Chapters 4 through 9 provide a tutorial introduction to C++’s builtin
types and the  basic facilities for constructing programs out of them.
Part II: Chapters 10 through 15 are a tutorial introduction to objectoriented
and generic programming  using C++.
Part III: Chapters 16 through 22 present the C++ standard library.
Part IV: Chapters 23 through 25 discuss design and software development issues.
Appendices: Appendices A through C provide language technical  details.

Chapter 1 provides an overview of this book, some hints about how to use it, and some background
information about C++ and its use. You are encouraged to skim through it, read what appears interesting,
and return to it after reading other parts of the book.

Chapters 2 and 3 provide an overview of the major concepts and features of the C++ programming
language and its standard library. Their purpose is to motivate you to spend time on fundamental
concepts and basic language features by showing what can be expressed using the complete
C++ language. If nothing else, these chapters should convince you that C++ isn’t (just) C and that
C++ has come a long way since the first and second editions of this book. Chapter 2 gives a highlevel
acquaintance with C++. The discussion focuses on the language features supporting data
abstractionobjectoriented programming, and generic programming.

 Chapter 3 introduces the  basic principles and major facilities of the standard library. This allows me to use standard library  facilities in the following chapters. It also allows you to use library facilities in exercises rather
than relying directly on lowerlevel,builtin features.

The introductory chapters provide an example of a general technique that is applied throughout
this book: to enable a more direct and realistic discussion of some technique or feature, I occasionally
present a concept briefly at first and then discuss it in depth later. This approach allows me to
present concrete examples before a more general treatment of a topic. Thus, the organization of
this book reflects the observation that we usually learn best by progressing from the concrete to the
abstract – even where the abstract seems simple and obvious in retrospect.
Part I describes the subset of C++ that supports the styles of programming traditionally done in
C or Pascal. It covers fundamental types, expressions, and control structures for C++ programs.
Modularity – as supported by namespaces, source files, and exception handling – is also discussed.
I assume that you are familiar with the fundamental programming concepts used in Part I. For
example, I explain C++’s facilities for expressing recursion and iteration, but I do not spend much
time explaining how these concepts are useful.
Part II describes C++’s facilities for defining and using new types. Concrete and abstract
classes (interfaces) are presented here (Chapter 10, Chapter 12), together with   operator overloading
(Chapter 11),   polymorphism, and the use of   class hierarchies  (Chapter 12, Chapter 15). Chapter 13
presents   templates, that is, C++’s facilities for defining families of types and functions. It demonstrates
the basic techniques used to provide containers, such as lists, and to support   generic programming.
Chapter 14 presents   exception handling, discusses techniques for error handling, and
presents strategies for fault tolerance. I assume that you either aren’t well acquainted with objecto riented
programming and generic programming or could benefit from an explanation of how the
main abstraction techniques are supported by C++. Thus, I don’t just present the language features
supporting the abstraction techniques; I also explain the techniques themselves. Part IV goes further
in this direction.
Part III presents the C++   standard library. The aim is to provide an understanding of how to use
the library, to demonstrate general design and programming techniques, and to show how to extend
the library. The library provides   containers  (such as l i s t , v e c t o r , and m a p ; Chapter 16, Chapter 17),
standard algorithms (such as s o r t , f i n d , and m e r g e ; Chapter 18, Chapter 19), strings (Chapter 20),
Input/Output (Chapter 21), and support for numerical computation (Chapter 22).
Part IV discusses issues that arise when C++ is used in the design and implementation of large
software systems. Chapter 23 concentrates on design and management issues. Chapter 24 discusses
the relation between the C++ programming language and design issues. Chapter 25 presents some
ways of using classes in design.
Appendix A is C++’s grammar, with a few annotations. Appendix B discusses the relation
between C and C++ and between Standard C++ (also called ISO C++ and ANSI C++) and the versions
of C++ that preceded it. Appendix C presents some languagetechnical
examples.
1.1.1 Examples and References [notes.examples]
    This book emphasizes program organization rather than the writing of algorithms. Consequently, I
avoid clever or hardertounderstand  algorithms. A trivial algorithm is typically better suited to
illustrate an aspect of the language definition or a point about program structure. For example, I
use a Shell sort where, in real code, a quicksort would be better. Often, reimplementation with a
more suitable algorithm is an exercise. In real code, a call of a library function is typically more
appropriate than the code used here for illustration of language features.
     Textbook examples necessarily give a warped view of software development. By clarifying and
simplifying the examples, the complexities that arise from scale disappear. I see no substitute for
writing realisticallysized programs for getting an impression of what programming and a programming
language are really like. This book concentrates on the language features, the basic techniques
from which every program is composed, and the rules for composition.
    The selection of examples reflects my background in compilers, foundation libraries, and simulations.
Examples are simplified versions of what is found in real code. The simplification is necessary
to keep programming language and design points from getting lost in details. There are no
‘‘cute’’ examples without counterparts in real code. Wherever possible, I relegated to Appendix C
language technical examples of the sort that use variables named x and y , types called A and B , and
functions called f () and g ().
    In code examples, a proportionalwidth font is used for identifiers. For example:
#i n c l u d e <i o s t r e a m >
i n t m a i n ()
{
    s t d :: c o u t << "H e l l o , n e w w o r l d !\ n ";
}
    At first glance, this presentation style will seem ‘‘unnatural’’ to programmers accustomed to seeing code in constant-width fonts. However, proportional-width fonts are generally regarded as better than constant-width fonts for presentation of text. Using a proportional-width font also allows me to present code with fewer illogical line breaks. Furthermore, my experiments show that most people find the new style more readable after a short while.
    Where possible, the C++ language and library features are presented in the context of their use
rather than in the dry manner of a manual. The language features presented and the detail in which
they are described reflect my view of what is needed for effective use of C++. A companion, The
Annotated C++ Language Standard, authored by Andrew Koenig and myself, is the complete definition of the language together with comments aimed at making it more accessible. Logically,
there ought to be another companion, The Annotated C++ Standard Library. However, since both
time and my capacity for writing are limited, I cannot promise to produce that.
1.1.2 Exercises [notes.exercises]
    Exercises are found at the ends of chapters. The exercises are mainly of the writeaprogram
variety. Always write enough code for a solution to be compiled and run with at least a few test cases.
The exercises vary considerably in difficulty, so they are marked with an estimate of their difficulty.
The scale is exponential so that if a (*1) exercise takes you ten minutes, a (*2) might take an
hour, and a (*3) might take a day. The time needed to write and test a program depends more on
your experience than on the exercise itself. A (*1) exercise might take a day if you first have to get
acquainted with a new computer system in order to run it. On the other hand, a (*5) exercise might
be done in an hour by someone who happens to have the right collection of programs handy.
Any book on programming in C can be used as a source of extra exercises for Part I. Any book
on data structures and algorithms can be used as a source of exercises for Parts II and III.
1.1.3 Implementation Note [notes.implementation]
The language used in this book is ‘‘pure C++’’ as defined in the C++ standard [C++,1997]. Therefore,  the examples ought to run on every C++ implementation. The major program fragments in
this book were tried using several C++ implementations. Examples using features only recently
adopted into C++ didn’t compile on every implementation. However, I see no point in mentioning
which implementations failed to compile which examples. Such information would soon be out of
date because implementers are working hard to ensure that their implementations correctly accept
every C++ feature. See Appendix B for suggestions on how to cope with older C++ compilers and
with code written for C compilers.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值