C++ Annotations Study Guide and Chapter Summaries – Frank B. Brokken (Version 13.04.01) BSCS/BSSE

BSCS and BSSE students who study object-oriented programming in C++ can use this guide to study “C++ Annotations” free from its author, Frank B. Brokken of the University of Groningen. It is the main textbook for his C++ programming courses, and it is written for people who already know C (or a language with C-like grammar) and want to make the move to C++. This page covers Version 13.04.01, which carries the dates 1994–2026, so it has been maintained since 1994.

The book is large. Its 26 chapters run to about 1,100 pages and go from namespaces, strings and streams through classes, memory allocation, exceptions, operator overloading, inheritance and polymorphism, to the standard library, templates, threads, coroutines and modules. It has no exercise sets, so it works best as the main reading beside your lectures, with practice questions taken from elsewhere. Use the chapter blocks below to see what each chapter really contains before you decide where to start.

Book Overview

CourseObject Oriented Programming (C++)
Degree ProgramsBSCS, BSSE
LevelUniversity / Undergraduate (needs C first)
EditionVersion 13.04.01 (1994–2026), the current version on the official page, released 21 February 2026
AuthorFrank B. Brokken
PublisherPublished at the University of Groningen, The Netherlands (ISBN 90 367 0470 7)
LanguageEnglish
Total Chapters26 chapters (Chapter 1 is a one-page overview of the chapters), no appendices
Pages1,123 pages in the A4 PDF
ExercisesNo exercise sets and no solutions
C++ StandardExamples use the latest standard, which the book calls C++26, including modules, concepts and coroutines
LicenseGNU General Public License, version 2 or later (stated in the legal notes distributed with the book)
FormatPDF, HTML and other formats, free from the official site and its zip archives

Chapter List

Chapter 2: Introduction

Difficulty: Easy · Key topics: C++ history, object-oriented programming, differences from C, function overloading, default arguments, nullptr, main

The chapter states that extensive knowledge of C is assumed, because the Annotations continue where C’s pointers, flow control and functions end. It lists what changed in recent versions, explains that C++ began at AT&T Bell Labs as a pre-compiler that produced C, and warns that C++ is not a perfect superset of C. It then weighs the usual claims made for C++ and object-oriented programming with some scepticism, sketches the object-based approach with a salary-administration example, and ends with a long tour of differences from C: main, end-of-line comments, strict prototypes, overloading, default arguments, nullptr, local variables and operand evaluation order.

Key Points:

  • sizeof('c') is 1 in C++ but equals sizeof(int) in C, and void func() means that the function takes no arguments, whereas in C it leaves the arguments unspecified.
  • Functions may share a name when their parameter lists differ (a const attribute also counts), but not when only the return type differs; compilers use name mangling internally to tell them apart.
  • Default arguments are supplied by the compiler at the call, so they make a program neither shorter nor faster.
  • show(0) and show(NULL) both select the int overload, while show(nullptr) selects the pointer overload.
  • Only two forms of main are allowed, int main() and int main(int argc, char **argv), and a missing return statement at the end of main is accepted.
  • C++ fixes the evaluation order for assignment (right to left) and shift operands (left to right); for most other binary operators it stays undefined.
  • Define local variables where they are needed and keep their scope as small as possible, including inside if, while and for conditions.

Practice Tip: Rename a small C file to .cc, compile it with g++ --std=c++26 -Wall and read every complaint, then add two overloads show(int) and show(char const *) and call show(0) and show(nullptr) to see which one runs.

Common Mistake: Assuming that C++ is a perfect superset of C, so any C file renamed to .cc must compile and behave the same.

Important Questions:

  • Is C++ a perfect superset of C? No. For example, sizeof('c') differs, empty parameter lists mean different things, and C++ requires strict prototypes for external functions, so some C code needs changes.
  • Why should nullptr be preferred over NULL or 0? NULL is usually just 0, so an overloaded call like show(NULL) picks the int version; nullptr is a real null pointer value and selects the pointer version.

Chapter 3: A First Impression Of C++

Difficulty: Medium · Key topics: const, namespaces, references, rvalue references, auto, enum class, casts, three-way comparison

This is the first long tour of language features that C lacks. It starts with stricter use of const, namespaces, the scope resolution operator and cin, cout and cerr, then shows functions inside structs and data hiding with public and private. The longest section adds references, rvalue references, lvalues and rvalues, strongly typed enumerations, initializer lists, designated initialization, auto with structured bindings, range-based for loops, raw string literals, binary constants, initializers in selection statements, attributes and the three-way comparison operator. It ends with new data types such as bool, size_t and std::byte, the four new-style casts and the list of C++ keywords.

Key Points:

  • A reference is an alias created by initialization; behind the scenes the compiler treats it as a const pointer, but you never write the indirection.
  • A function returning a reference allows chains such as cout << "Hello" << '\n', because each insertion returns a reference to cout.
  • An rvalue reference, written Type &&, binds to an anonymous temporary, and an overload taking one is chosen when an unnamed value such as 18 is passed.
  • In a class members are private by default, in a struct they are public by default; data hiding is the point of the distinction.
  • auto deduces a variable’s type from its initializer, and the old use of auto as a storage class is no longer supported.
  • C-style casts are deprecated; use static_cast, const_cast, reinterpret_cast or dynamic_cast so the compiler can check that the cast makes sense.
  • Constructor notation such as Type(expression) is not a cast; it asks the compiler to construct an anonymous object.

Practice Tip: Write receive(int &) and receive(int &&), call them with a variable and with the literal 18, and print which one ran; then rename the parameter inside the second one and pass it on to see that a named parameter counts as an lvalue.

Common Mistake: Thinking that an rvalue reference parameter is still a temporary inside the function; once it has a name, the compiler treats it as a named value.

Important Questions:

  • What is the difference between an lvalue reference and an rvalue reference? An lvalue reference (Type &) refers to a named object; an rvalue reference (Type &&) binds to anonymous temporary values and lets overloads treat them differently.
  • Why use C++ casts instead of the C cast syntax? The new casts each have a narrow purpose, so the compiler can verify that the cast is sensible, and the cast is easy to find in the source.

Chapter 4: Namespaces

Difficulty: Medium · Key topics: namespace, using directive, Koenig lookup, std::chrono, duration, time_point, std::filesystem, path

The chapter begins with a teacher who needs a cos function that takes degrees, and shows how a namespace gives such a function its own declarative region instead of an awkward new name. It explains that namespaces are open and may be spread over several source files, how to refer to their entities with qualification, a using declaration or a using directive, how Koenig lookup finds functions through argument types, and how nesting and aliases work. The rest of the chapter is two library tours: std::chrono with ratios, durations, clocks and time points, and std::filesystem with path, file_status, directory iterators, space_info and filesystem_error.

Key Points:

  • A namespace is declared with namespace name { ... }; it cannot be defined inside a function body, but it can be reopened in several files and the pieces are united.
  • Koenig lookup means that an unqualified function call also searches the namespaces of its argument types; if arguments come from two namespaces that both have a matching function, the call is ambiguous.
  • A definition in one namespace can change which function a call in another namespace selects, so namespaces can still surprise you.
  • std::chrono provides four clocks: system_clock (wall clock), steady_clock, high_resolution_clock and file_clock.
  • Every clock has a static now() returning a time_point, and a std::duration is expressed through a std::ratio that sets its resolution.
  • std::filesystem::path holds names of file system entries, and directory_iterator and recursive_directory_iterator visit directory entries.

Practice Tip: Record steady_clock::now() before and after a loop, subtract the two time points, and print the result in milliseconds with duration_cast.

Common Mistake: Putting using namespace std; in a header file, which forces every file that includes it to accept all standard names.

Important Questions:

  • What is Koenig lookup? It is the rule that a function called without a namespace is also looked up in the namespaces of its arguments’ types, so fun(value) can find FBB::fun when value is an FBB::Value.
  • Why can one namespace be defined in several source files? Namespaces are open: every block with the same name adds its entities to the same namespace, which is how a library spreads one namespace over many headers.

Chapter 5: The ‘string’ Data Type

Difficulty: Easy · Key topics: std::string, operators, iterators, member functions, conversions, string_view

The chapter argues that std::string should replace the traditional C string functions, since many buffer overruns, boundary errors and allocation problems in C programs come from misusing them. It explains that string objects are class-type variables used through member functions, but that operators such as = and == usually give clearer code than members like compare. It then gives a long reference for std::string covering initializers, iterators, operators, member functions and conversion functions. The final section introduces std::string_view, a light-weight wrapper that refers to existing characters, with its extra members and its operator for sv literals.

Key Points:

  • C++ deprecates the traditional C library functions that work on NTB strings in favour of std::string objects.
  • Prefer if (string1 == string2) over string1.compare(string2) == 0; operators make the code easier to read.
  • A string_view does not hold its own copy of the characters; it refers to the characters it was constructed from.
  • string_view cannot append or insert characters, but it can change existing characters through the index operator or at.
  • string_view adds remove_prefix and remove_suffix, and the literal suffix sv creates one from text.
  • Both string and string_view provide hashing, so either can be a key in associative containers.

Practice Tip: Build a string_view over a local character array, return it from a function and print it; then repeat with a static array and compare the output.

Common Mistake: Keeping a string_view alive after the string or array behind it has been destroyed or changed, which leaves it pointing at unpredictable data.

Important Questions:

  • Why use std::string instead of C character arrays? It manages its own memory and offers operators and members, which avoids the buffer overruns, boundary errors and allocation mistakes that plague C string functions.
  • How does string_view differ from string? A string owns and can extend its characters; a string_view is only a light-weight view of characters stored elsewhere, so it is cheap to copy but depends on the source staying valid.

Chapter 6: The IO-stream Library

Difficulty: Medium · Key topics: ios_base, ios, streambuf, formatting flags, ostream, ifstream, ostringstream, redirection

C++ replaces C’s FILE approach with an input/output library built on classes. The chapter starts with the special headers and the foundation classes ios_base and ios, explains condition states, and covers formatting of output and input with member functions, flags and the std::quoted manipulator. Output is then explained through ostream, ofstream with its open modes, ostringstream and put_time; input through istream, ifstream and istringstream, including positioning, copying and coupling streams. The chapter closes with moving streams, redirecting streams by sharing streambuf objects, and reading and writing the same stream. It also explains why class names such as basic_ios usually appear as ios or wios.

Key Points:

  • Most I/O classes are templates with names such as basic_ios, and using declarations like using ios = basic_ios<char> give the names you normally write.
  • The insertion operator << and extraction operator >> work on streams and return a reference to the stream, which makes chaining possible.
  • Condition states tell you whether the last operation succeeded, reached the end of input or failed.
  • ofstream and ifstream take open modes that decide whether a file is created, truncated, appended to or read.
  • ostringstream and istringstream let you format or parse text in memory instead of using a file.
  • A stream can be redirected by letting it share another stream’s streambuf through ios::rdbuf.

Practice Tip: Write a few numbers into an ostringstream using setw and setfill, take the resulting string, and read the numbers back with an istringstream.

Common Mistake: Reading input without checking the stream’s state afterwards, so a failed extraction is used as if it had worked, or a loop never ends.

Important Questions:

  • How does the C++ I/O library differ from C’s stdio? It is based on classes and templates, uses overloaded << and >> operators that know the type being handled, and can be extended for user-defined types and other character types.
  • What does ios::rdbuf allow you to do? It lets two streams share one streambuf, so text written to one stream goes to the other’s destination, which is how a stream is redirected inside a program.

Chapter 7: Classes

Difficulty: Medium · Key topics: class, constructor, composition, delegating constructors, defaulted and deleted members, const member functions, inline, mutable

The chapter introduces the class as C++’s main data structuring device, enforcing data hiding and encapsulation by default. It covers constructors with and without arguments and the order in which objects are constructed, then the surprising ambiguity between an object definition and a function declaration. It continues with composition and member initializers, data member initializers, delegating constructors, uniform initialization and defaulted and deleted members. It also explains const member functions and anonymous objects, inline functions and variables, local classes, the mutable keyword, header file organization and the use of sizeof on class data members.

Key Points:

  • A class is a kind of struct whose content is hidden from the outside by default, while a struct exposes its members by default.
  • In the Annotations’ convention all data members start with d_, which keeps them visually apart from member functions.
  • Objects are constructed in order: the global object first, then the local objects in the order they are defined.
  • Data d1(); declares a function returning Data, not an object; the compiler then complains that d1 is of non-class type Data().
  • Data members that are const or references must be initialized in the constructor’s member initializer list.
  • A const object can only call const member functions, and mutable lets a specific data member change even there.
  • = default and = delete let you keep or remove members that the compiler would otherwise generate.

Practice Tip: Give a class a constructor that prints a message, then create one global object and two local objects in different functions and check that the output order matches the order described above.

Common Mistake: Writing Data d1(); to create a default-constructed object, which silently declares a function instead.

Important Questions:

  • Why does Data d1(); not create an object? The compiler reads it as a function declaration returning Data; write Data d1; or Data d1{} to create an object.
  • What is a const member function for? It promises not to modify the object, so it can be called on const objects and through const references.

Chapter 8: Static Data And Functions

Difficulty: Easy · Key topics: static data members, static member functions, constexpr, initialization of static const data

Some information belongs to a whole class rather than to each object, such as the name of a startup directory or a flag recording that initialization has already happened. The chapter explains that C solves this with file-level static variables or obscure names, and that C++ solves it with static members. It covers private and public static data, initializing static const data, generalized constant expressions with constexpr, and static member functions with their calling conventions. It points out that a static member function has no this pointer and therefore cannot be virtual.

Key Points:

  • A static data member exists once for the whole class and is shared by all its objects.
  • Placing a static member in the private section hides it from code outside the class.
  • A static member function has no this pointer, so it cannot be a virtual function.
  • A static member function can be called without an object, using ClassName::function().
  • constexpr asks for a value or function result that is a constant expression, so the compiler can compute it at compile time.
  • The book advises defining and initializing every static data member, const or not, in a single source file, because in-class initialization of static const data is not guaranteed to work with every compiler setting.

Practice Tip: Add a private static counter to a class, increase it in the constructor and decrease it in the destructor, and print a public static function that returns its value while several objects come and go.

Common Mistake: Declaring a non-inline static data member in the class and never defining it in a source file, which ends in a linker error.

Important Questions:

  • Why can a static member function not be virtual? A virtual function is an ordinary member with a this pointer, which it uses to find the object’s real type; a static member has no such pointer.
  • When should you use a static data member? When all objects need to share one value, for example a flag that records whether a one-time initialization has been done.

Chapter 9: Classes And Memory Allocation

Difficulty: Hard · Key topics: new and delete, destructor, copy constructor, assignment operator, swap, move semantics, copy elision, unrestricted unions

The chapter contrasts C’s malloc and free with the operators new and delete, which are type safe, call constructors and destructors and are configurable through set_new_handler. It covers allocating, deleting and enlarging arrays, raw memory and placement new, then the destructor, the assignment operator, the this pointer and the copy constructor. Swapping is used to make assignment safe, and move semantics are introduced with move constructors, move assignment, move-only classes and design implications. The chapter ends with copy elision and return value optimization, unrestricted unions and aggregate data types, and a conclusion on the rules for classes that manage memory.

Key Points:

  • new needs a type, so no sizeof expression is required, it calls the constructor, and a failed allocation is not reported by a NULL return.
  • Memory from new[] must be released with delete[], not plain delete.
  • A class that allocates memory it controls must implement at least a destructor, a copy constructor and an overloaded assignment operator.
  • Swapping is used to make the assignment operator safe against failures and self-assignment.
  • A move constructor has a parameter of type Class &&; it is chosen for anonymous temporaries and lets the new object take over the data instead of copying it.
  • The compiler may use copy elision wherever possible, but it is never required to.
  • An unrestricted union can hold class-type members, but the surrounding class then has to take care of the destructor and assignment itself.

Practice Tip: Write a small buffer class that owns a new[] array, add a destructor, copy constructor, swap-based assignment and move constructor, each printing a message, and watch which ones run when you return the object from a function.

Common Mistake: Relying on the compiler-generated copy for a class with a raw pointer member, so two objects end up deleting the same memory.

Important Questions:

  • Which members must a class implement when it manages its own memory? A destructor, a copy constructor and an overloaded assignment operator; a move constructor is optional but useful for efficiency.
  • What problem does move semantics solve? It avoids copying data from temporary objects: the destination takes over the data pointed to by the temporary, which is cheaper and works for types that cannot be copied.

Chapter 10: Exceptions

Difficulty: Hard · Key topics: throw, try, catch, noexcept, standard exceptions, exception guarantees, function try blocks, constructors and destructors

The chapter starts from C’s ways of reacting to trouble: printing a message, returning an error code, calling exit, or using setjmp and longjmp for non-local exits. It presents exceptions as the preferred, controlled alternative and covers throw, the empty throw statement, try blocks, catch clauses and the default catcher, and noexcept. It then looks at iostreams and exceptions, the standard exception classes, system_error with error_category and error_condition, and exception_ptr. The last sections define the basic, strong and nothrow guarantees, and explain function try blocks and why exceptions in constructors and destructors need care.

Key Points:

  • Calling exit to deal with a problem skips the destructors of local objects, and setjmp/longjmp disrupt program flow completely; exceptions are the preferred alternative.
  • An empty throw; inside a catch clause rethrows the exception being handled.
  • A default catcher, catch (...), handles any exception that earlier clauses did not match.
  • The basic guarantee means no resources are leaked, the strong guarantee means the program state is unchanged after a failure, and the nothrow guarantee means no exception can be thrown at all.
  • Exceptions must not leave a destructor; in the book’s Cupboard example, a class with two members whose destructors both throw ends in a call to terminate() and the program aborts.
  • noexcept marks functions that promise not to throw, and std::exception_ptr lets an exception be carried to another place.
  • A constructor that throws leaves a partly built object, so members already constructed are destroyed and the code must not leak resources.

Practice Tip: Give a class a constructor and destructor that print messages, create two objects in nested functions, throw from the innermost function and watch the destructors run while the stack unwinds to the catch clause.

Common Mistake: Letting an exception escape from a destructor, which can end the program with an abort instead of a normal catch.

Important Questions:

  • What are the three exception guarantees? The basic guarantee (no leaks), the strong guarantee (state unchanged if the operation fails) and the nothrow guarantee (the operation cannot throw).
  • Why is exception handling preferred over setjmp and longjmp? Exceptions give a controlled non-local return that still runs destructors of local objects, while the C mechanism simply jumps and skips the levels in between.

Chapter 11: More Operator Overloading

Difficulty: Hard · Key topics: operator[], insertion and extraction, conversion operators, explicit, increment, new and delete, function objects, lambda expressions

After the assignment operator in chapter 9, this chapter looks at operator overloading in general. It builds an IntArray to show how operator[] works as both lvalue and rvalue, adds multi-argument index operators, and overloads insertion and extraction operators. Conversion operators, the explicit keyword, prefix and postfix increment, binary operators, reference-qualified members and the three-way comparison operator follow. The chapter then overloads new, delete and their array forms, introduces function objects and manipulators, lambda expressions with their syntax, the open() case for file streams, user-defined literals and a table of overloadable operators.

Key Points:

  • operator[] is useful as both lvalue and rvalue; the book notes that index operators do not normally check bounds, and that a const version should return Type const &.
  • Insertion and extraction operators for your own types are written as free functions, because the stream stands on the left-hand side.
  • A conversion operator turns an object into another type, and explicit stops the compiler from using it or a constructor silently.
  • Prefix and postfix increment are told apart by a dummy int parameter in the postfix form.
  • Most binary operators come in a plain form such as + that returns a value and a compound form such as += that usually returns a reference to the object; operator<=> covers comparisons.
  • A function object is an object of a class that defines operator(); it can carry state, unlike a plain function.
  • A lambda expression defines an unnamed function object in place, with a capture list, parameters and a body.

Practice Tip: Add both a non-const and a const operator[] to an IntArray class, assign through one on a normal object, and read through the other on a const object to see each version being chosen.

Common Mistake: Leaving single-argument constructors and conversion operators non-explicit, so the compiler converts values behind your back.

Important Questions:

  • How do you tell prefix and postfix ++ apart when overloading? The postfix version takes an extra unused int parameter; the prefix version takes none.
  • What does the explicit keyword do? It forbids implicit conversions through that constructor or conversion operator, so the conversion has to be written out.

Chapter 12: Abstract Containers

Difficulty: Medium · Key topics: pair, vector, list, deque, map, set, unordered containers, complex

The chapter introduces the standard containers as abstract because the data type they store is left open when they are written and named later in angle brackets, as in pair. After a short explanation of the notation used, it covers pair, then each available container in turn: array, vector, list, queue, priority_queue, deque, map and multimap, set and multiset, and stack. An intermezzo on hashing leads to unordered_set, unordered_multiset, unordered_map and unordered_multimap, followed by heterogeneous lookup. The chapter ends with the complex container for complex numbers.

Key Points:

  • Container types are written with angle brackets, for example pair<int, string>, and each container needs its own header such as <vector>.
  • array has a fixed size, while vector is an expandable array that supports the index operator.
  • list is a linked list that can be traversed from the front or the back.
  • map stores key and value pairs, and multimap allows several values for one key.
  • set keeps unique keys and multiset may keep duplicates; the unordered versions use hashing instead of ordering.
  • queue, priority_queue and stack restrict access to match their names, and deque allows work at both ends.
  • Version 13.04.00 of the Annotations added the intermezzo on hashing and now covers unordered_set before unordered_map.

Practice Tip: Count how often each word appears in a short text using map<string, size_t>, print it, then switch to unordered_map and compare the order of the output.

Common Mistake: Using a map’s index operator just to check whether a key exists, which inserts a new default element if it does not.

Important Questions:

  • How do map and unordered_map differ? A map keeps its keys in sorted order, while unordered_map is a hash table with no useful order but usually faster lookups.
  • When would you choose list over vector? When elements are often inserted or removed in the middle and iterators must stay valid; for fast indexing and compact storage, vector is the usual choice.

Chapter 13: Inheritance

Difficulty: Medium · Key topics: base class, derived class, access rights, constructors and destructors, multiple inheritance, conversions

The chapter contrasts C’s top-down function hierarchy with deriving a class from an older class, so that the new class inherits its functionality without holding it as a data member. It distinguishes composition (a class contains another) from derivation (a class is, or is implemented in terms of, another), and discusses whether deep hierarchies are desirable. It covers public, protected and private access, promoting access rights, and the constructors of derived classes including move operations and inherited constructors. Destructors, redefining member functions, multiple inheritance, conversions between base and derived classes by object and by pointer, and new[] with non-default constructors complete it.

Key Points:

  • A derived class is built on top of its base class: the base class constructor runs first, and base class destructors run after the derived destructor.
  • A derived class constructor should initialize its base class through a base class initializer instead of assigning values later.
  • Public, protected and private derivation decide how the base class members are seen by code outside and by further derived classes.
  • Access rights of inherited members can be promoted with a using declaration.
  • Assigning a derived object to a base class object copies only the base part, while a base class pointer may point to a derived object but sees only the base interface.
  • Multiple inheritance lets a class have several base classes, which brings ambiguities that must be resolved explicitly.
  • Constructors can be inherited, and redefining a member function in a derived class hides the base version with the same name.

Practice Tip: Make three classes Vehicle, Land and Car whose constructors and destructors print their names, create a Car and check that construction and destruction orders are mirror images.

Common Mistake: Assigning a derived object to a base class variable and expecting the derived data to survive, when only the base part is copied.

Important Questions:

  • In what order are constructors and destructors called in a class hierarchy? Base class constructors run first, then the derived constructor; destruction runs in the opposite order, derived first and then the base.
  • What is the difference between composition and inheritance? Composition means one class has an object of another as a data member; inheritance means the new class is a kind of, or is implemented in terms of, the old class.

Chapter 14: Polymorphism

Difficulty: Hard · Key topics: virtual functions, virtual destructors, pure virtual functions, override, RTTI, streambuf, vtable, virtual constructors

Polymorphism implements the Liskov Substitution Principle: a derived class object can be used through a base class pointer or reference, and the object’s real type decides which member function runs. The chapter covers virtual functions, constructors of polymorphic classes, virtual destructors, pure virtual functions and abstract classes, and explicit overrides. It then looks at virtual functions with multiple inheritance, virtual base classes, run-time type identification with dynamic_cast and typeid, and when inheritance is the right tool. Later sections derive classes from streambuf, build a polymorphic exception class, show how vpointers and vtables work, and explain virtual constructors.

Key Points:

  • The Liskov Substitution Principle says that a derived class object may be passed to code expecting a base class pointer or reference; streams passed to functions expecting an ostream are the familiar example.
  • With a base class pointer, only a function declared virtual is chosen by the real object type; otherwise the pointer’s type decides.
  • A base class needs a virtual destructor, otherwise delete through a base pointer calls only the base destructor and leaks what the derived class owns.
  • A pure virtual function makes a class abstract, so it cannot be used to create objects.
  • A virtual base class stops a class from appearing twice when it is reached through two inheritance paths.
  • Run-time type identification uses dynamic_cast and typeid.
  • Each object with virtual functions holds one hidden vpointer, and each class has one vtable, which is the small memory and speed cost of polymorphism.

Practice Tip: Call a member function through a Vehicle * that points to a Truck, once with virtual and once without, and also delete it through the base pointer with and without a virtual destructor, printing a message in each destructor.

Common Mistake: Forgetting the virtual destructor in a base class, so objects deleted through base pointers are only partly destroyed.

Important Questions:

  • Why does a polymorphic base class need a virtual destructor? So that delete on a base class pointer calls the destructor of the actual derived object first and then the base destructor.
  • How is polymorphism implemented? Objects of classes with virtual functions contain a hidden vpointer to a per-class vtable that holds the addresses of the virtual functions, and a call looks the function up there at run time.

Chapter 15: Friends

Difficulty: Easy · Key topics: friend functions, extended friend declarations, encapsulation, data hiding

This is a very short chapter on the friend keyword. It starts from the rule that private members are only accessible to the members of their class, which enforces encapsulation and data hiding, and explains that friend gives chosen functions access without throwing that principle away. It shows that some functions, such as the operators of chapter 11, must be defined outside the class interface and may still need that access. The second section covers extended friend declarations, where the class keyword no longer has to be given for a friend class unless the compiler has not yet seen its name. Friendship among classes is left to chapters 17 and 21.

Key Points:

  • A friend function is granted access to a class’s private members although it is not a member of the class.
  • Using friend does not abandon data hiding; it extends the class’s interface to a few chosen functions.
  • There should be a well-defined conceptual reason before you declare friendship.
  • Operators that must be defined outside the class, such as insertion and extraction operators, are typical cases.
  • With extended friend declarations you can write friend Friend; without class when the name is already known to the compiler.
  • The explicit class is still required if the compiler has not yet seen the friend’s name.

Practice Tip: Write a free function operator<< for a small class, first using only public accessors and then as a friend, and note what the friend version could do that the first one could not.

Common Mistake: Declaring many friends to avoid writing accessors, which makes other code depend on the class’s internal data.

Important Questions:

  • Does a friend declaration break encapsulation? Not by itself: the class decides which functions are friends, so the access is granted deliberately and stays part of the class’s design.
  • What changed with extended friend declarations? The class keyword is no longer needed in a friend declaration of a class whose name the compiler has already seen.

Chapter 16: Classes Having Pointers To Members

Difficulty: Hard · Key topics: pointers to members, .* and ->*, static members, polymorphism trade-off

Pointers to members point to locations inside objects rather than to objects, and they can be used to configure the behaviour of objects of a class. The chapter weighs this against polymorphism: passing an object of a derived class gives easy, flexible configuration but limits access to data members, while pointers to members give somewhat less flexible configuration with direct access. It starts with an example using a class String, then shows how to define pointers to members, how to use them on objects and on pointers to objects, how pointers to static members differ, and how large such pointers are.

Key Points:

  • A pointer to a member is defined by prefixing the pointer notation with the class and scope operator, as in char const *(String::*d_sp)() const.
  • A pointer to a member can point to a data member or a member function, and matching signatures are required.
  • Pointers to members are used with the member selection operators .* and ->* on an object or an object pointer.
  • Static members have no object, so their addresses are stored in ordinary function pointers, and pointers to members cannot hold them.
  • Pointers to members can have a different size from ordinary pointers.
  • A pointer to a member can choose behaviour inside a class, while polymorphism configures behaviour from outside.

Practice Tip: Store pointers to two const member functions of a String class in an array, then call one through an index with (object.*array[i])() to select behaviour at run time.

Common Mistake: Dropping the parentheses in a call such as (obj.*ptr)(), which changes the meaning and does not compile.

Important Questions:

  • What is a pointer to a member? A value that identifies a member of a class rather than an address of an object; it is used together with an object to reach that member.
  • When can a pointer to a member be preferable to polymorphism? When you want to configure behaviour with direct access to the class’s data members, without the friend declarations and extra classes that the polymorphic design would need.

Chapter 17: Nested Classes

Difficulty: Medium · Key topics: nested class, access to private members, nested enumerations, virtual constructors

Nested classes are classes defined inside other classes, used when the inner class has a close conceptual relationship to the surrounding class, as string::iterator does. The chapter explains how members of nested classes are defined, how a class can be declared first and defined later, and how nested class members can reach all members of a surrounding object when given a pointer or reference to it. It states that the surrounding class has no special privileges toward its nested classes. Enumerations can be nested too, including empty enumerations. The chapter finishes by revisiting virtual constructors from chapter 14 with the base class nested inside Clonable.

Key Points:

  • A nested class may be placed in the public, protected or private section, which sets who can see it.
  • Members of a nested class can access all members of an object of the surrounding class when they are given a pointer or reference to it.
  • The surrounding class has no special privileges with respect to its nested class.
  • A nested class can be declared in the surrounding class and defined later, outside it.
  • Enumerations can be nested in a class to keep their names inside the class scope.
  • The virtual constructor example becomes tidier when Base is nested in Clonable, emphasizing their close relationship.

Practice Tip: Write a small Surround class with a nested class that holds an int, give the nested class a member that prints a private member of a Surround object passed to it, and then try the reverse to see the missing privilege.

Common Mistake: Assuming that the surrounding class may use the private members of its nested class, when it has no special access.

Important Questions:

  • Why use a nested class? When the inner type only makes sense together with the surrounding class, for example an iterator type of a container, nesting keeps the name in scope and shows the relationship.
  • Who can reach private members when classes are nested? Members of the nested class can reach members of the surrounding object they are given, but the surrounding class gets no special access to the nested class.

Chapter 18: The Standard Template Library

Difficulty: Hard · Key topics: function objects, iterators, unique_ptr, shared_ptr, regular expressions, random numbers, tie, optional

The chapter describes the Standard Template Library as containers, generic algorithms, iterators, function objects, allocators and adapters, and concentrates on using the algorithms rather than building templates. It starts with predefined function objects and then iterators, including insert iterators and iterators for istream and ostream objects. Smart pointers get long sections: unique_ptr, shared_ptr and the make_unique and make_shared helpers, plus classes with pointer data members. It then covers comparison classes, regular expressions with the std::regex mini language and matching functions, random number generators and statistical distributions, std::tie and optional return values.

Key Points:

  • Predefined function objects include arithmetic, relational and logical ones, and std::not_fn negates a predicate.
  • Insert iterators and iterators for streams, such as istream_iterator and ostream_iterator, let algorithms read from and write to places other than containers.
  • A unique_ptr deletes its object when it goes out of scope; it is moved, not copied, and should only point to dynamically allocated memory.
  • A shared_ptr keeps a count of owners and deletes the object when the last owner is gone; make_shared and make_unique create the object and the smart pointer together.
  • regex_match matches the full text, regex_search finds a partial match, and regex_replace changes the target string.
  • A random number generator is combined with a statistical distribution, and the chapter lists distributions from Bernoulli to Weibull.
  • std::optional offers a clean way to return either a value or nothing, instead of pointers, bool flags or pairs.

Practice Tip: Read integers from cin with an istream_iterator into a vector and print them back with an ostream_iterator using copy.

Common Mistake: Trying to copy a unique_ptr, or creating two smart pointers from the same raw pointer, instead of moving it or copying a shared_ptr.

Important Questions:

  • What is the difference between unique_ptr and shared_ptr? A unique_ptr has exactly one owner and is moved, while a shared_ptr allows several owners and frees the memory when the last one disappears.
  • What is the difference between regex_match and regex_search? regex_match succeeds only if the whole text matches the expression, while regex_search succeeds if any part of the text matches.

Chapter 19: The STL Generic Algorithms

Difficulty: Medium · Key topics: algorithm and numeric headers, execution policies, sort, find, transform, accumulate, set algorithms, heap algorithms

Generic algorithms work on many data types while keeping type safety, in contrast with C’s callback functions that take void pointers and need casts. The chapter explains that algorithms need the algorithm header, or the numeric header for the operators category, and that they should be used wherever possible instead of hand-written loops. It begins with execution policies for parallel execution, then lists the algorithms alphabetically, from accumulate and adjacent_find through copy, count, find, for_each, merge, partition, remove, reverse, rotate, sample and search to the set algorithms, sort, transform, unique and heap algorithms, each with its prototype and an example.

Key Points:

  • Include <algorithm> for most algorithms, but <numeric> for the operators category such as accumulate.
  • Generic algorithms use iterator ranges, so a call like sort(begin, end) works for many container types without casts.
  • Some algorithms accept an execution policy as first argument, which needs the <execution> header and, in the book’s examples, linking with -ltbb.
  • The book advises to search the generic algorithms before writing your own code for common tasks.
  • Searching algorithms like binary_search, lower_bound and equal_range expect sorted ranges.
  • remove and unique rearrange elements but do not shrink the container by themselves.
  • Set algorithms such as set_union and set_intersection work on sorted ranges.

Practice Tip: Put some repeated numbers in a vector, then sort, unique and erase to remove duplicates, and print the vector after each step.

Common Mistake: Calling remove or unique and expecting the container to get shorter, without erasing the leftover elements.

Important Questions:

  • Why use generic algorithms instead of your own loops? They are tested, work with any suitable iterators and element types, and state the intention (sort, find, copy) so the code is shorter and clearer.
  • What must be true for the binary search algorithms? The range has to be sorted according to the ordering used in the search, otherwise the result is not meaningful.

Chapter 20: Multi Threading

Difficulty: Hard · Key topics: thread, jthread, mutex, condition_variable, atomic, future, promise, osyncstream

The chapter notes that the 1998 standard ignored threads, and that C++ now offers a high-level interface built on the pthreads facilities, though coverage is necessarily incomplete. It introduces std::thread and the this_thread namespace, thread_local data, joining and exceptions, and jthread with stop callbacks. It then covers mutexes, shared mutexes, locks, deadlocks and scoped locks, condition variables with an example, atomic types, and a threaded quicksort. Shared states lead to future, shared_future, async, packaged_task and promise. The chapter closes with transactional memory and synchronizing output to streams with syncbuf and osyncstream.

Key Points:

  • A thread that has started and is not detached must be joined, or the program aborts; an exception in the parent can skip join(), so the join should be wrapped in an object.
  • A jthread joins automatically, and its function can be stopped in some situations.
  • Shared data is protected with a mutex and a lock_guard; a compound statement limits the guard’s lifetime.
  • condition_variable lets threads wait for an event instead of looping.
  • std::atomic<Type> works for built-in and trivial types and removes the need for a separate mutex.
  • async, packaged_task and promise all deliver results through a shared state that a future reads.
  • osyncstream keeps the output of several threads from mixing.

Practice Tip: Start four threads that each add 100000 to a shared int, run it without protection, then with a mutex, then with std::atomic<int>, and compare the printed totals.

Common Mistake: Sharing a variable between threads without any synchronization, which leads to corrupted values that only show up now and then.

Important Questions:

  • What is the difference between thread and jthread? A jthread joins its thread automatically when it is destroyed and can be asked to stop, while a thread must be joined or detached by your code.
  • When is an atomic variable better than a mutex? For simple shared values such as counters and flags, because it needs no separate mutex and lock object.

Chapter 21: Function and Variable Templates

Difficulty: Hard · Key topics: function templates, deduction, specialization, SFINAE, if constexpr, static_assert, std::function, variable templates

Templates let the compiler generate code tailored to the types a program uses, called instantiations. The chapter covers defining function templates, template type and non-type parameters, auto, decltype, declval and late-specified return types, reference wrappers and unnamed types as template arguments. It explains the template parameter deduction rules with their lvalue, qualification and base-class transformations, then declaring, instantiating, overloading and specializing function templates. Static assertions, numeric limits, polymorphous wrappers for function objects and the compilation model follow. The chapter ends with the function selection mechanism, SFINAE, if constexpr, a summary of declaration syntax and template variables.

Key Points:

  • A template is a recipe; the compiler generates the real function, called an instantiation, from it at compile time.
  • Template parameter deduction applies transformations: lvalue transformations, qualification transformations and a transformation to a base class.
  • Explicit template types such as func<Int>(10) can be given when the compiler cannot deduce them.
  • Function templates can be overloaded and specialized for deviating types, but the book warns against too many specializations.
  • SFINAE means that a failed substitution in a template header removes that template from consideration instead of causing an error.
  • if constexpr chooses between code paths at compile time, and static_assert checks conditions at compile time.
  • std::function is a polymorphous wrapper for function objects, and variable templates make a variable depend on a type.

Practice Tip: Write a template max-like function, call it with two ints, two doubles and an int with a double, note the compile error in the last case, and then fix it with an explicit type like <double>.

Common Mistake: Putting only the declaration of a function template in a header and its definition in a source file, which leaves the linker without the instantiation it needs.

Important Questions:

  • What is template parameter deduction? The compiler works out the template types from the types of the actual arguments in a call, applying fixed transformation rules, so you usually do not have to name them.
  • What does SFINAE stand for and why is it useful? Substitution Failure Is Not An Error; it lets overloaded templates be disabled for types that do not fit, so the compiler simply picks another candidate.

Chapter 22: Class Templates

Difficulty: Hard · Key topics: class templates, non-type parameters, partial specialization, variadic templates, fold expressions, tuples, static polymorphism, iterators

Class templates separate algorithms from the data they work on, as with the vector, stack and queue containers. The chapter starts with template argument deduction and then builds a CirQue circular queue to show how class templates are defined, with non-type parameters, member templates, default parameters, declarations, generic lambdas and template parameter initialization. It covers static data members, typename, specializations and partial specializations with a Matrix example, then variadic templates, perfect forwarding, the unpack operator and fold expressions. Tuples, friend declarations, class template derivation, static polymorphism, nesting and the construction of random access and reverse iterators complete the chapter.

Key Points:

  • In a class template only the data type has to be given when an object is defined, as in stack<int> iStack.
  • Non-type template parameters let a constant such as a size be part of the type.
  • Member templates allow a member function of a class template to be a template itself.
  • Partial specializations adapt a template for a family of types, as in the Matrix class with specializations for rows and columns.
  • Variadic templates take any number of template arguments; perfect forwarding passes arguments on unchanged, and fold expressions combine a parameter pack with an operator.
  • Static polymorphism uses templates instead of virtual functions, which avoids vpointers and late binding.
  • A class template can be a friend in several ways: unbound, bound to specific types, or as a non-template function.

Practice Tip: Write a small circular queue template with the capacity as a non-type parameter, instantiate it for int and string, and push more items than it holds to see how it behaves.

Common Mistake: Forgetting typename before a dependent type name inside a template, so the compiler cannot tell whether a name is a type.

Important Questions:

  • How do class templates compare with polymorphism? Both postpone decisions: polymorphism lets derived classes supply the details at run time, while templates let the type be chosen at compile time with no virtual-call overhead.
  • What does a partial specialization do? It provides a different implementation of a class template for a subset of possible arguments, for example all pointer types or a matrix with one row.

Chapter 23: Advanced Template Use

Difficulty: Hard · Key topics: template metaprogramming, template template parameters, policy classes, traits, TypeList, expression templates, concepts

Templates can do integer arithmetic, make decisions and repeat actions at compile time, so the compiler can be asked to compute almost anything, although not at record speed. The chapter first covers subtleties such as name resolution for base class members and the ::template syntax. It then explains template metaprogramming with values, alternatives and recursion, user-defined literals, template template parameters with policy classes and alias templates. Trait classes, error code enumerations, the strong guarantee with noexcept and conversions to class types follow, then TypeList processing, expression templates and a long final section on concepts and requirements.

Key Points:

  • Compile-time programming with templates rests on three abilities: integer arithmetic, compile-time decisions and repetition by recursion.
  • A template template parameter lets a template take another template as an argument; policy classes use it to build structure from policies.
  • Alias templates give a short name to a family of types, and trait classes ask questions about a type at compile time.
  • A TypeList is a list of types handled by templates, with operations such as length, search, selecting, prefixing and erasing.
  • Expression templates avoid the temporary vectors and repeated passes over the elements that arise when several vectors are added in one expression such as one + two + three + four.
  • Concepts are templates that are never instantiated; they check at compile time that types meet requirements.
  • Requirements come in four forms: simple, type, compound and nested, and the standard library provides predefined concepts.

Practice Tip: Define a concept Addable that requires operator+, constrain a function template with it, and call it with a type that has no + to see the error message.

Common Mistake: Forgetting the template keyword in constructs like obj.template func<int>(), so the compiler reads the angle bracket as a less-than sign.

Important Questions:

  • What can templates compute at compile time? Integer values, decisions between alternatives and repeated actions through recursion, which together can express almost any calculation, such as prime numbers.
  • What is a concept? A named set of compile-time requirements on template types, checked when the template is used, which gives clearer errors than failures deep inside a template.

Chapter 24: Coroutines

Difficulty: Hard · Key topics: co_yield, co_await, co_return, promise_type, Awaitable, Awaiter, coroutine handle, finite state automaton

The chapter starts from a Fibonacci generator written as a class with a next member, and shows how a coroutine does the same job by suspending and resuming. It explains the handler class, the State class that must be known as promise_type, and the members that control suspension. It then shows coroutines embedded in classes with Reader and Writer handlers, awaitables, awaiters and co_await, and how the state can be accessed from inside a coroutine. Finite state automata, recursive coroutines, coroutine iterators and visiting directories follow, and the chapter ends by comparing functions with coroutines.

Key Points:

  • A coroutine is a function that can suspend itself with co_yield or co_await and be resumed later, keeping its data between activations.
  • The handler class’s State class must be publicly known as promise_type.
  • The State class provides members such as get_return_object and the suspension members; suspend_always keeps the coroutine suspended until resumed.
  • co_await expects an awaitable expression, and await_transform in the State class can convert an expression into one.
  • A coroutine’s data lives on the heap between resumptions, so repeated calls need no repeated stack handling.
  • The chapter builds a finite state automaton, recursive coroutines and a directory visitor with coroutines.

Practice Tip: Write the book’s motivating example, a coroutine that yields the next Fibonacci number each time you resume it, and compare it line by line with the class version using a next member.

Common Mistake: Treating a coroutine like an ordinary function and calling it again each time; the handler object keeps it alive, and you should resume it instead.

Important Questions:

  • What is a coroutine and how does it differ from a function? A coroutine can suspend and resume while keeping its state, so it cooperates with its caller, whereas an ordinary function starts afresh at every call.
  • What does co_await do? It suspends the coroutine on an awaitable expression, and the awaiter decides what happens at suspension and when the coroutine continues.

Chapter 25: Modules

Difficulty: Hard · Key topics: module interface unit, export, import, gcm.cache, partitions, module mapping, headers

The chapter explains why header files became a burden: they hold type definitions as well as declarations, need include guards, and are processed again for every source file that includes them. It notes that a header including iostream and string makes g++ 14.2.0 read over 900,000 bytes per source, and that precompiled headers help but can exceed 25 MB. It then introduces the module syntax with export module, module and export import, module interface units, the gcm.cache directory, namespaces and templates in modules, partitions with a Math example, module mapping and the design conventions used in the Annotations.

Key Points:

  • Module syntax uses export module Name;, module Name; and export import Name;, and partitions use Name:Partition.
  • A module’s interface unit replaces its header file, and it must be compiled before the sources that use it.
  • The compiler stores a compiled interface unit as a .gcm file in a gcm.cache directory, and importing sources need access to it.
  • Compiling with g++ needs the -fmodules-ts option in the book’s examples, and system headers can also be module-compiled.
  • Only exported components can be used outside the module; others are available to the module alone.
  • The book suggests keeping interface units small and declarations separate from definitions, with one component per source file.

Practice Tip: Create a small module with an exported function, compile its interface unit first with -fmodules-ts, then compile and link a main that imports it and see the gcm.cache directory appear.

Common Mistake: Compiling the importing source file before the module interface unit, so the compiler cannot find the compiled module.

Important Questions:

  • Why were modules introduced? Headers are textually reprocessed for every source file and need include guards, while a module is compiled once into a binary form that importers read, which speeds up builds.
  • What is a module partition? A sub-component of a module, written as Module:Partition, that holds facilities which may be completely inaccessible outside the module.

Chapter 26: Concrete Examples

Difficulty: Hard · Key topics: streambuf for file descriptors, fork, pipes, binary operators and CRTP, reverse_iterator, flexc++, bisonc++

The last chapter shows complete C++ programs, classes and templates that put earlier chapters to work, roughly following their order. It builds streambuf-derived classes for reading and writing file descriptors, including one-character and n-character buffers, seeking and fixed-size field extraction. It wraps the Unix fork system call in a Fork class with Pipe, ParentSlurp, Selector and Monitor classes for talking to several children. It then adds binary operators using the CRTP, distinguishes lvalues and rvalues in operator[], implements a reverse_iterator and uses flexc++ and bisonc++ to build a scanner and parser, which assumes some knowledge of flex and bison.

Key Points:

  • File descriptors are not part of the C++ standard, but classes derived from std::streambuf can let streams read and write them, including pipes and sockets.
  • A Fork class wraps the fork system call, and the Pipe, ParentSlurp, Selector and Monitor classes support communication with one or several child processes.
  • The CRTP and operator function templates can add binary operators to many classes without rewriting them.
  • operator[] can be written to distinguish between use as an lvalue and as an rvalue.
  • A reverse_iterator can be implemented on top of an existing iterator type.
  • The scanner and parser sections use flexc++ and bisonc++, which generate C++ classes and assume that you know the ideas behind flex and bison.

Practice Tip: Pick one example, such as the Pipe class, type it in rather than pasting it, compile it on Linux or WSL, and add a print statement in each member to follow the parent and child.

Common Mistake: Trying to run the fork and pipe examples on a system without Unix-style process support and blaming the code when they fail to build.

Important Questions:

  • Why derive a class from streambuf for file descriptors? Streams read and write through a streambuf, so a streambuf that talks to a descriptor lets ordinary stream code work with files, pipes and sockets.
  • What do flexc++ and bisonc++ do? They generate C++ classes for a scanner and a parser from specification files, so complex input can be processed without writing the recognition code by hand.

How to Study This Book

This is a very large book: 26 numbered chapters and 1,123 pages in the A4 PDF, with no parts, appendices or exercise sets. Chapter 1 is a one-page list of what the other chapters contain, so it has no block above. The book is written for knowledgeable users of C (or a language with C-like grammar) and says plainly that it does not cover C’s own basic grammar, so be comfortable with pointers, loops and functions in C before you start. Do not read it like a novel. Use it as the main text beside your OOP lectures, and read the chapters in the order your course reaches them.

Start with Chapters 2 and 3. Chapter 2 is a short, readable list of what is different from C, and Chapter 3 introduces references, rvalue references, auto, casts and class basics, which almost every later chapter relies on. Then read Chapters 4, 5 and 6 on namespaces, strings and streams. The book itself says the stream library can be used before classes are covered, so these chapters give you working programs early. In Chapter 4 you can skip the long std::filesystem part on a first pass.

The core of an object-oriented programming course is Chapters 7, 8 and 9, followed by 13 and 14. Read them in that order. Chapter 7 gives you classes and constructors, Chapter 8 is short, and Chapter 9 is the hardest early chapter, because the destructor, copy constructor, assignment operator and move operations only make sense together. Re-read its conclusion once you reach Chapter 13. Chapters 13 and 14 are inheritance and polymorphism, and the long section on deriving from streambuf (14.8) can wait until you need it.

Chapters 10 and 11 fit between these. Exceptions (Chapter 10) matter for any real program, and Chapter 11 on operator overloading also introduces function objects and lambda expressions, which the library chapters use heavily. Chapter 12 on containers needs only a small grasp of templates, so you can read it early and use vector and map in your own programs. Chapters 15, 16 and 17 are short and specialised: friends, pointers to members and nested classes. Read them when a lecture or a project demands them.

Chapters 18 and 19 are the Standard Template Library and generic algorithms. Read Chapter 18 for smart pointers first, then use Chapter 19 as a reference to look algorithms up rather than reading every entry. The template chapters, 21, 22 and 23, should be read in order, and they are long: Chapter 22 alone is roughly 100 pages. Concepts are in section 23.13 and are only worth reading after you are comfortable with Chapter 21.

Chapters 20, 24 and 25 on multi-threading, coroutines and modules are advanced topics. Some courses stop before them. Modules and coroutines need a recent compiler: the book’s examples use g++ with the -fmodules-ts option and the C++26 standard flag. The book says it targets the latest standard, so some older lecture slides will show different syntax or ignore these features. Chapter 26 is a collection of larger programs; the fork and pipe examples assume a Unix-like system, so use Linux, macOS or WSL.

The book has no exercise sets and no solutions. For practice, work through your lecture exercises, type in the examples from the chapter you are reading, and change them to see what breaks. If you need worked exercises, the C++ exercises key book linked below is a good partner. Remember also that the book is an annotation to a course, not a complete reference: its author says it does not cover every aspect of C++.


Used In These Programs

This book is used for the Object Oriented Programming (C++) course in: BS Computer Science · BS Software Engineering. Browse all Object-Oriented Programming books, all C++ books or all Computer Science books.

Who Should Read This

This book is for BSCS and BSSE students whose object-oriented programming course uses C++ and who already know C or a similar language. It suits the semester when you move from procedural programming to classes, inheritance, templates and the standard library, and it is also good for self-learners who want an author who explains why C++ works as it does. It is not a first programming book: if you are still learning loops and functions, start with Programming Fundamentals or learn the OOP ideas first in Think Java, then return here. For solved practice problems, use Key Book to OOP C++ Programming Exercises, since this book has no exercises of its own. It is also not meant as a quick exam-revision pamphlet, because most chapters run to dozens of pages.


Applicable Universities

This book is useful for students at Pakistani universities offering BS Computer Science or BS Software Engineering with an object-oriented programming course in C++, including Punjab University, Virtual University, COMSATS, FAST, UET, NUST, and other HEC-recognized institutions.

Official Copy of C++ Annotations

The author publishes the C++ Annotations free on his official page, which links an HTML version to read online and zip archives of the book in PDF, PostScript and other formats. Click below to open the official page and choose the format you want. This page only links to it and does not host the book.

→ Visit Official Page

FAQs

Is C++ Annotations free?

Yes. The author offers it free on his official page. The PDF says the book is published under the GNU General Public License, and the legal notes that come with it name version 2 or later and encourage you to share it and publish it on your own website. The project’s GitLab repository labels its LICENSE file as the GNU Affero General Public License v3.0, so check the repository if you plan to reuse the text. This page links to the official site and does not host the file.

Which version is this, and is it up to date?

It is Version 13.04.01, dated 1994–2026 and released on 21 February 2026. The first number changes only for a major rewrite, the middle number when new information is added, and the last number for small fixes such as typos. The “What’s new” section shows recent additions such as a rewritten Modules chapter, a coroutines chapter and a section on the std::quoted manipulator.

How many chapters and exercises does it have?

There are 26 numbered chapters and about 1,100 pages in the A4 PDF, followed by an index. Chapter 1 is a one-page list of what the other chapters cover. The book has no exercise sets and no solutions. It only occasionally leaves a detail as an exercise to the reader, so use your course exercises or a separate exercise book for practice.

Is it good for complete beginners?

No. The book says it is meant for knowledgeable users of C and assumes extensive knowledge of C, including pointers, basic flow control and writing functions. It does not teach C’s basic grammar. If you are new to programming, begin with a gentler book and come back to this one when you are comfortable with C.

Does it cover modern C++ such as move semantics, lambdas, threads, concepts, coroutines and modules?

Yes. It covers rvalue references and move semantics, lambda expressions, smart pointers, multi-threading, concepts, coroutines and a full chapter on modules. It says it assumes the latest standard, and uses the C++26 flag in its examples, so you need a recent compiler to try everything. It does not cover every aspect of C++, and it leaves out rare features such as digraphs.

Does it cover object-oriented programming concepts such as inheritance and polymorphism?

Yes. Chapters 7 to 9 cover classes, constructors, destructors, copying and moving, Chapter 13 covers inheritance and Chapter 14 covers polymorphism with virtual functions, abstract classes and run-time type identification. It explains the ideas through C++ code and also covers templates as an alternative to polymorphism, so it works as a course text but is much more detailed than most lecture notes.

Related Books

C++ Annotations gives you a complete, carefully maintained guide to C++ from the author who teaches it, as long as you bring a working knowledge of C and some patience. Browse more Computer Science books for the rest of your semester.

C++ Annotations (Version 13.04.01, 1994–2026) by Frank B. Brokken, published at the University of Groningen, The Netherlands (ISBN 90 367 0470 7). The book states that it is published under the GNU General Public License, and its legal notes name version 2 or later. Official sources: https://fbb-git.gitlab.io/cppannotations/ and https://gitlab.com/fbb-git/cppannotations-zip. This page links to the official site and does not host or copy the book.

Leave a Comment