[ ERCB Home |
New |
Feature |
Brief |
DDJ |
Letters |
Links
]
[an error occurred while processing this directive]
Vital Statistics
 |
| Title | C++ Primer, Third Edition |
| Authors | Stanley B. Lippman and Josée Lajoie |
| Publisher | Addison-Wesley Longman
http://www.awl.com/ |
| Copyright | 1998 |
| ISBN | 0-201-82470-1 |
| Pages | 1237 |
| Price | $45.95 |
|
The Most Educational Path To Learning C++
That C++ is a complex programming language is a well-known fact.
Its support for a wide spectrum of diverse programming paradigms
(especially after the revamping occurred in the last circa five years
period) and countless high- and low-level techniques are hardly
recognizable in any other language with an equally strong grip on
production projects at all levels in the industry. This wealth does
not come without a price, however. And the price to pay is just that
-- complexity and greater inclination to committing mistakes,
ascribable to the reduced possibility for the compiler to recognize
unknowingly incorrect semantics in the code written by the
programmer. More limited languages offer less flexibility, but this
also means that there is a less broad range of techniques expressible
and, consequently, the development tool has higher odds of catching
the unwanted mistakes.
During the last fifteen years, the power factor seems to have
outperformed the complexity factor, marking the track for massive
adoption of C++ in all sorts of serious application realms. Hundreds
of books have been published covering every single aspect of the
language, including its syntactic and semantic aspects, its effective
adoption in small- and large-scale projects, and its most resounding
features as well as its most worrying pitfalls.
In the lot, a pretty numerous subset aims at teaching the
fundamentals of the language in course style, suitable for adoption
as manuals in academic computer science classes, training sessions,
and independent study endeavors. They generally assume only a basic
knowledge of computer programming and possibly familiarity with
another programming language (not necessarily C or an object-oriented
one) and promise to walk the reader into discovering, understanding,
and harnessing the full power of C++. Of the many in this category,
C++ Primer is by far my favorite.
Am I being heretic by dethroning the universally embraced bible of
C++, Bjarne Stroustrup's The C++ Programming Language? Yes and
no. Both are very valuable texts, with the main difference lying in
the usage instructions. C++ Primer is a book you can read and
learn from nearly cover to cover, whereas The C++ Programming
Language is a reference with which you can look up limited chunks
of information on an as-needed basis, consciously putting your trust
in the creator of the language, but you will hardly digest it all at
once. Which one is preferable as a companion to a C++-intensive
course? If the course aims at actually teaching the C++ language
inside out, Lippman and Lajoie's text makes for more useful reading
and will surely help the students refreshing the modules of the
course with a descriptive tone and an equilibrate pace. If the course
aims at perfecting the skills of an already solid C++ developer, the
punctuality and authority of Stroustrup seems to me a better fit.
Concentrating both completeness and readability in a single
resource, C++ Primer sits at the top of my personal ranking
for the most educational C++ books. It is one of the few very thick
books that I really like and in which the remarkable number of pages
actually makes sense, as they allow the authors to offer clear
down-to-earth explanations and examples of every bit, thereby guiding
the reader into mastering the fundamentals of C++, starting from the
most basic elements (data types, statements, expressions, functions)
and up to a discreet level of complication (classes, template
programming, inheritance, and polymorphism). Basically nothing is
given for granted, every concept and piece of information flows
progressively and is described with all of its surrounding context. I
was gladly surprised by seeing how the authors have managed to
furnish some useful bits of C++ design considerations (e.g. glancing
at the most important programming paradigms supported by the
language, ranging from procedural to object-oriented to
template-driven approaches), which, whilst not deep or particularly
original, will likely come in handy to C++ neophytes.
On the other hand, this is not an advanced book -- the word
"primer" in the title is a sign of the honesty of the authors, who
are keen to admitting the inappropriateness of this book for already
seasoned C++ users. Despite this, the presentation of such complex
topics as the Standard Template Library and the portion on the
generic algorithms, now an integral part of the language, are
sufficiently complete and readable for the needs of the average
programmer.
If you are looking at studying C++ from the ground floor rather
than mastering its most intricate peculiarities, C++ Primer
will turn out to be a choice you won't regret -- and very good
value for your time and money.
-- Davide Marcato (marcato@programmers.net or
http://www.DavideMarcato.com)
Table of Contents
- Preface ..... xiii
- Structure of This Book.....xiv
- Changes to the Third Edition.....xviii
- The Future of C++.....xix
- Acknowledgments.....xx
- Acknowledgments to the Second Edition.....xx
- Bibliography.....xxi
- Part I: C++, An Overview.....1
- Chapter 1: Getting Started.....5
- 1.1: Problem Solving.....5
- 1.2: The C++ Program.....6
- 1.3: Preprocessor Directives.....13
- 1.4: A Word About Comments.....17
- 1.5: A First Look at Input/Output.....19
- Chapter 2: A Tour of C++.....23
- 2.1: The Built-In Array Data Type.....23
- 2.2: Dynamic Memory Allocation and Pointers.....26
- 2.3: An Object-Based Design.....30
- 2.4: An Object-Oriented Design.....41
- 2.5: A Generic Design.....51
- 2.6: An Exception-Based Design.....58
- 2.7: An Array by Any Other Name.....62
- 2.8: The Standard Array Is a Vector.....68
- Part II: The Basic Language.....73
- Chapter 3: The C++ Data Types.....75
- 3.1: Literal Constant.....75
- 3.2: Variables.....79
- 3.3: Pointer Types.....88
- 3.4: String Types.....93
- 3.5: const Qualifier.....102
- 3.6: Reference Types.....105
- 3.7: The bool Type.....110
- 3.8: Enumeration Types.....111
- 3.9: Array Types.....114
- 3.10: The vector Container Type.....121
- 3.11: complex Number Types.....125
- 3.12: Typedef Names.....126
- 3.13: volatile Qualifier.....127
- 3.14: The pair Type.....128
- 3.15: Class Types.....129
- Chapter 4: Expressions.....141
- 4.1: What Is an Expression?.....141
- 4.2: Arithmetic Operators.....143
- 4.3: Equality, Relational, and Logical
Operators.....146
- 4.4: Assignment Operators.....149
- 4.5: Increment and Decrement Operators.....154
- 4.6: Complex Number Operations.....155
- 4.7: The Conditional Operator.....159
- 4.8: The sizeof Operator.....160
- 4.9: The new and delete Expressions.....162
- 4.10: Comma Operator.....164
- 4.11: The Bitwise Operators.....164
- 4.12: bitset Operations.....168
- 4.13: Precedence.....172
- 4.14: Type Conversions.....175
- 4.15: A Stack Class Example.....185
- Chapter 5: Statements.....189
- 5.1: Simple and Compound Statements.....189
- 5.2: Declaration Statement.....191
- 5.3: The if Statement.....194
- 5.4: The switch Statement.....202
- 5.5: The for Loop Statement.....210
- 5.6: The while Statement.....214
- 5.7: The do while Statement.....216
- 5.8: The break Statement.....218
- 5.9: The continue Statement.....220
- 5.10: The goto Statement.....220
- 5.11: A Linked List Example.....222
- Chapter 6: Abstract Container Types.....249
- 6.1: Our Text Query System.....250
- 6.2: A vector or a list?.....254
- 6.3: How a vector Grows Itself.....256
- 6.4: Defining a Sequence Container.....260
- 6.5: Iterators.....265
- 6.6: Sequence Container Operations.....269
- 6.7: Storing Lines of Text.....273
- 6.8: Finding a Substring.....276
- 6.9: Handling Punctuation.....282
- 6.10: A String by Any Other Format.....285
- 6.11: Additional String Operations.....288
- 6.12: Building a Text Location Map.....294
- 6.13: Building a Word Exclusion Set.....305
- 6.14: The Complete Program.....308
- 6.15: Multimap and Multiset.....318
- 6.16: Stack.....321
- 6.17: Queue and Priority Queue.....323
- 6.18: Revisiting Our iStack Class.....324
- Part III: Procedural-Based Programming.....329
- Chapter 7: Functions.....331
- 7.1: Overview.....331
- 7.2: Function Prototype.....334
- 7.3: Argument Passing.....338
- 7.4: Returning a Value.....356
- 7.5: Recursion.....361
- 7.6: Inline Functions.....363
- 7.7: Linkage Directives: extern "C" .....364
- 7.8: main(): Handling Command Line Options .....367
- 7.9: Pointers to Functions .....378
- Chapter 8: Scope and Lifetime.....389
- 8.1: Scope.....389
- 8.2: Global Objects and Functions.....395
- 8.3: Local Objects.....402
- 8.4: Dynamically Allocated Objects.....405
- 8.5: Namespace Definitions .....420
- 8.6: Using Namespace Members .....434
- Chapter 9: Overloaded Functions.....443
- 9.1: Overloaded Function Declarations.....443
- 9.2: The Three Steps of Overload Resolution.....456
- 9.3: Argument Type Conversions .....458
- 9.4: Details of Function Overload Resolution .....474
- Chapter 10: Function Templates.....489
- 10.1: Function Template Definition.....489
- 10.2: Function Template Instantiation.....497
- 10.3: Template Argument Deduction .....500
- 10.4: Explicit Template Arguments .....505
- 10.5: Template Compilation Models .....509
- 10.6: Template Explicit Specialization .....514
- 10.7: Overloading Function Templates .....520
- 10.8: Overload Resolution with Instantiations .....522
- 10.9: Name Resolution in Template Definitions .....531
- 10.10: Namespaces and Function Templates .....538
- 10.11: Function Template Example.....542
- Chapter 11: Exception Handling.....547
- 11.1: Throwing an Exception.....547
- 11.2: The Try Block.....551
- 11.3: Catching an Exception.....555
- 11.4: Exception Specifications.....564
- 11.5: Exceptions and Design Issues.....568
- Chapter 12: The Generic Algorithms.....571
- 12.1: Overview.....571
- 12.2: Using the Generic Algorithms.....575
- 12.3: Function Objects.....586
- 12.4: Revisiting Iterators.....594
- 12.5: The Generic Algorithms.....603
- 12.6: When Not to Use the Generic Algorithms.....606
- Part IV: Object-Based Programming.....611
- Chapter 13: Classes.....613
- 13.1: Class Definition.....614
- 13.2: Class Objects.....621
- 13.3: Class Member Functions.....624
- 13.4: The Implicit this Pointer.....636
- 13.5: Static Class Members.....641
- 13.6: Pointer to Class Member.....649
- 13.7: Union: A Space-Saving Class.....658
- 13.8: Bit-field: A Space-Saving Member.....663
- 13.9: Class Scope .....665
- 13.10: Nested Classes .....672
- 13.11: Classes as Namespace Members .....683
- 13.12: Local Classes .....687
- Chapter 14: Class Initialization, Assignment, and
Destruction.....689
- 14.1: Class Initialization.....689
- 14.2: The Class Constructor.....691
- 14.3: The Class Destructor.....703
- 14.4: Class Object Arrays and Vectors.....709
- 14.5: The Member Initialization List.....716
- 14.6: Memberwise Initialization .....723
- 14.7: Memberwise Assignment .....729
- 14.8: Efficiency Considerations .....732
- Chapter 15: Overloaded Operators and User-Defined
Conversions.....737
- 15.1: Operator Overloading.....737
- 15.2: Friends.....748
- 15.3: Operator =.....751
- 15.4: Operator [ ].....754
- 15.5: Operator ( ).....755
- 15.6: Operator ->.....756
- 15.7: Operators ++ and --.....759
- 15.8: Operators new and delete.....763
- 15.9: User-Defined Conversions.....772
- 15.10: Selecting a Conversion .....782
- 15.11: Overload Resolution and Member Functions
.....795
- 15.12: Overload Resolution and Operators .....801
- Chapter 16: Class Templates.....811
- 16.1: Class Template Definition.....812
- 16.2: Class Template Instantiation.....820
- 16.3: Member Functions of Class Templates.....829
- 16.4: Friend Declarations in Class Templates.....833
- 16.5: Static Data Members of Class Templates.....839
- 16.6: Nested Types of Class Templates.....841
- 16.7: Member Templates .....844
- 16.8: Class Templates and Compilation Model .....849
- 16.9: Class Template Specializations .....856
- 16.10: Class Template Partial Specializations .....860
- 16.11: Name Resolution in Class Templates .....862
- 16.12: Namespaces and Class Templates .....865
- 16.13: A Template Array Class.....867
- Part V: Object-Oriented Programming.....877
- Chapter 17: Class Inheritance and Subtyping.....879
- 17.1: Defining a Class Hierarchy.....882
- 17.2: Identifying the Members of the Hierarchy.....890
- 17.3: Base Class Member Access.....900
- 17.4: Base and Derived Class Construction.....908
- 17.5: Base and Derived Class Virtual Functions.....919
- 17.6: Memberwise Initialization and Assignment
.....943
- 17.7: A UserQuery Manager Class.....948
- 17.8: Putting It Together.....958
- Chapter 18: Multiple and Virtual Inheritance.....965
- 18.1: Setting the Stage.....965
- 18.2: Multiple Inheritance.....970
- 18.3: Public, Private, and Protected
Inheritance.....977
- 18.4: Class Scope under Inheritance.....985
- 18.5: Virtual Inheritance .....993
- 18.6: A Multiple, Virtual Inheritance Example
.....1005
- Chapter 19: Uses of Inheritance in C++.....1021
- 19.1: Run-Time Type Identification.....1021
- 19.2: Exceptions and Inheritance.....1033
- 19.3: Overload Resolution and Inheritance .....1051
- Chapter 20: The iostream Library 1063
- 20.1: The Output Operator<<.....1067
- 20.2: Input.....1072
- 20.3: Additional Input/Output Operators.....1083
- 20.4: Overloading the Output Operator
<<.....1090
- 20.5: Overloading the Input Operator >>.....1095
- 20.6: File Input and Output.....1097
- 20.7: Condition States.....1107
- 20.8: String Streams.....1109
- 20.9: Format State.....1112
- 20.10: A Strongly Typed Library.....1121
- Appendix: The Generic Algorithms Alphabetically.....1123
- accumulate().....1125
- adjacent_difference().....1126
- adjacent_find().....1127
- binary_search().....1128
- copy().....1129
- copy_backward().....1130
- count().....1131
- count_if().....1133
- equal().....1134
- equal_range().....1136
- fill().....1138
- fill_n().....1139
- find().....1140
- find_if().....1141
- find_end().....1143
- find_first_of().....1144
- for_each().....1145
- generate().....1146
- generate_n().....1147
- includes().....1148
- inner_product().....1149
- inplace_merge().....1150
- iter_swap ().....1152
- lexicographical_compare().....1153
- lower_bound().....1154
- max().....1156
- max_element().....1156
- min().....1156
- min_element().....1157
- merge().....1158
- mismatch().....1159
- next_permutation().....1161
- nth_element().....1162
- partial_sort().....1163
- partial_sort_copy().....1164
- partial_sum().....1165
- partition().....1167
- prev_permutation().....1168
- random_shuffle().....1169
- remove().....1170
- remove_copy().....1170
- remove_if().....1171
- remove_copy_if().....1172
- replace().....1173
- replace_copy().....1173
- replace_if().....1174
- replace_copy_if().....1174
- reverse().....1175
- reverse_copy().....1176
- rotate().....1177
- rotate_copy().....1177
- search().....1178
- search_n().....1180
- set_difference().....1181
- set_intersection().....1181
- set_symmetric_difference().....1182
- set_union().....1182
- sort().....1184
- stable_partition().....1185
- stable_sort().....1186
- swap().....1187
- swap_range().....1188
- transform().....1189
- unique().....1190
- unique_copy().....1191
- upper_bound().....1193
- Heap Algorithms.....1194
- make_heap().....1194
- pop_heap().....1195
- push_heap().....1195
- sort_heap().....1195
- Index.....1199
Excerpts from C++ Primer
("Chapter 3 -- The C++ Data Types"), page 88
"Every pointer has an associated type. The difference between
pointers of different data types is neither in the representation of
the pointer nor in the values (addresses) the pointers may hold
-- these are generally the same for all data pointers. The
difference, rather, is in the type of the object being addressed. The
type of a pointer instructs the compiler how to interpret the memory
found at a particular address as well as how much memory that
interpretation should span.
· An int pointer addressing memory location 1000 on a
32-bit machine spans the address space 1000-1003.
· A double pointer addressing memory location 1000 on a
32-bit machine spans the address space 1000-1007.
Here are some examples of pointer definitions:
[
]
A pointer is defined by prefixing the identifier with the
dereference operator (*). In a comma-separated definition list, the
dereference operator must precede each identifier intended to serve
as a pointer. In the following example, lp is intended as a pointer
to an object of type long, and lp2 is interpreted as a data object of
type long and not as a pointer:
long *lp, lp2;
In this next example, fp is interpreted as a data object of type
float and fp2 is interpreted as a pointer to a float:
float fp, *fp2;
For clarity, it is preferable to write
string *ps;
rather than
string* ps;
The possibility is that the programmer, later wishing to define a
second string pointer, may incorrectly modify this definition as
follows:
//oops: ps2 is not a string pointer
string* ps, ps2;
A pointer can hold a value of 0, indicating that it points to no
object, or the address of a data object of the same type.
[
]"
("Chapter 12 -- The Generic Algorithms"), page 603
"The first two arguments to all the generic algorithms (with the
necessary fistful of exceptions that make the rule) are a pair of
iterators, generally referred to as first and last, marking the range
of elements within the container or built-in array over which to
operate. The element range notation (sometimes called a
left-inclusive interval) is usually written as
// to be read as: includes first and
// each element up to but not including last
[first, last)
indicating that the range begins with first and ends with but does
not include last. When
first == last
the range is said to be empty.
A requirement of the iterator pair is that it must be possible to
reach last beginning with first through repeated application of the
increment operator. However, the compiler cannot itself enforce this;
failure to meet this requirement results in undefined run-time
behavior -- usually an eventual core dump of the program.
Each algorithm's declaration indicates the minimum category of
iterator support it requires (see Section 12.4 for a brief discussion
of the five iterator categories). find(), for example -- which
implements a one-pass, read-only traversal over a container --
minimally requires an InputIterator. It can also be passed a
Forward-, Bidirectional-, or RandomAccessIterator. Passing it an
OutputIterator results in a error. Errors in passing an invalid
category of iterator to an algorithm are not guaranteed to be caught
at compile-time, because the iterator categories are not actual
types. Rather, they are type parameters passed to the function
template.
Some algorithms support multiple versions; one uses a built-in
operator, and a second accepts either a function object or a pointer
to function providing an alternative implementation of that operator.
unique(), for example, by default compares two adjacent elements
using the equality operator of the underlying element type of the
container. If, however, the underlying element type does not provide
an equality operator or if we wish to define element equality
differently, we can pass either a function object or a pointer to a
function that provides the intended semantics. Other algorithms,
however, are separated into two uniquely named instances, the
predicate instance in each case ending with the suffix if, as in
find_if(). [
]
Quick Rating
|
Readability
|
|
|
Originality
|
|
|
Organization
|
|
|
Accuracy
|
|
|
Consistency
|
|
|
Depth
|
|
|
Timeliness
|
|
|
Editing
|
|
|
Design
|
|
|
Overall Value
|
|
Explanation of ERCB rating scale: No stars = unacceptable, 1
Star = marginal, 2 Stars = average, 3 Stars = above average, 4 Stars
= exceptional.
Copyright ©1999 Electronic Review of Computer Books
Created 6/25/1999 / Last modified 6/25/1999 / webmaster@ercb.com