Many Computer Science programmes teach two programming languages in the
first years of the core curriculum. The first language is selected for
its simple semantics and ease of use so that students can learn about
fundamental computing topics such as control structures, functions,
recursion, abstract data types, etc. without bothering about the
underlying hardware and operating system aspects. C++ is not a good
language for this purpose.
The second language is then chosen to complement the first in that its
teaching provides an opportunity to study the aspects that are
abstracted from in the first language: efficiency, run-time support
including operating system interfaces and memory management, compilation
and linking, etc. Choosing an industrially relevant and wide-spectrum
language has obvious additional advantages. C++ is an ideal
candidate for this purpose as it exposes the student to all of the above
aspects while at the same time it provides powerful abstraction
mechanisms supporting generic and object-oriented programming.
This textbook presents a concise yet reasonably complete introduction
to the C++ programming language and its abstraction mechanisms. The
reader is expected to be familiar with basic programming concepts,
making this book suitable, for example, for second year computer science
C++ is a wide spectrum language that provides a confusing
number of features, which I've tried to streamline
by providing a hierarchy of concepts centred around the notions
of types and type constructors.
The structure of the book reflects the gradual introduction of these
Each time, examples are provided to motivate the inclusion of a feature
into the language.
- simple data objects and functions,
- simple built-in types and operations,
- (user-defined) abstract data types,
- built-in type constructors,
- user-defined type constructors, and
- extending types using inheritance.
The text also touches on the implementation of the various concepts.
This is necessary to motivate the decisions that have influenced
the design of C++, thus making it easier to really understand the language.
Moreover, knowing a bit about the implementation is also useful
when assessing the efficiency aspects of alternative designs.
The programs from the book, as well as other illustrative programs and
case studies can be found on the
Chapter 1 (pp. 1-24) presents the basic concepts of C++: data
objects, values, types and variables, references, object construction,
functions; basic lexical and syntactic (scope, namespaces) aspects of
the language; compilation and linking.
Chapter 2 (pp. 25-36) covers built-in types
and associated operators; it also introduces conversions and
Functions are covered in Chapter 3 (pp. 37-50): control flow,
local and static data objects, overloading.
Chapter 4 (pp. 51-82) introduces user-defined types, concentrating on
the class construct as a suitable mechanism for abstract data type
Pointers, constant objects and arrays are presented as
built-in type constructors (i.e. functions that map types to types)
in Chapter 5 (pp. 83-116).
A taxonomy of object memory management alternatives is also presented.
Chapter 6 (pp. 117-136)
presents templates as user-defined
type constructors. Template argument deduction, overloading
and specialization are also covered.
Generic programming using abstractions such as iterators
is covered in
Chapter 7 (pp. 137-182).
The chapter includes an
overview of several standard library containers, algorithms
Chapter 8 (pp. 183-204) deals
with derivation as a mechanism
to support subtypes, polymorphism and object-oriented programming.
Chapter 9 (pp. 205-216) covers exceptions.
Chapter 10 (pp. 217-240) presents
the iostream library, including
its design and how to implement new stream classes.
Chapter 11 (pp. 241-264) motivates and describes good design
practices: developing coherent abstractions that are independent
The site also contains a set of
transparencies and a list of errata.
This book was greatly improved through the comments and suggestions of students
and colleagues who read preliminary versions:
Marina De Vos,
Koen De Winter,
Any mistakes that remain are of course my own.
Thu Jul 5 10:49:24 CEST 2001