Previous reading guide     Next reading guide

AP Reading guide - Lecture 4 and 5

This is a reading guide to Part III (chapter 16-25) of The C++ Prog. Lang. (4. edition).

Chaper 16 can be read as a tutorial on C++ classes - and the philosophy behind them. I recommend that you read most of it.

Chapter 17 is long chapter about constructors, destructors, copy constructors and move constructors. Initialization of data member is rather complex issue in C++11, because of the new initializer {} notation. This is clearly reflected in chapter 17. The distinction between copying and moving is discussed in this chapter (17.5). You may skip details here and there (such as 17.3.4 and 17.6) but most of the chapter is actually quite important.

Chapter 18 describes operator overloading of 'normal operators', whereas chapter 19 describes overloading af 'more special operators'. Chapter 18 is relatively straightforward to read (if you are interested in the topic of operator overloading of course). Section 18.3 is an example of class complex with overloaded operators. It serves an example of a concrete class (see 16.3). Notice the possibility of creating new literals be means of overloading (18.3.4), further detailed in 19.2.6. This is a nice 'little idea'. 18.4 is about conversions (nicely overviewed in the 10 lines just above 18.4.1).

Chapter 19 also starts with overloading. In 19.2, subscript overloading (19.2.1) is straightforward. Function call overloading in 19.2.2 relates to function objects (see also 3.4.3), which is both interesting and a little challenging in its means of expression (the for-each example). 19.2.3 - 19.2.4 about dereferencing -> and increment/decrement are rather special, so you may skip these sections. Section 19.2.5 tells how to redefine new and delete, either globally or in a class. In 19.2.6 we can read about a C++11 feature: User-defined literals - quite nice, and maybe a little surprising. Section 19.3 is a rather LARGE example (class string) - read it if you are interested. In 19.4 the chapter turns 180 degrees, to the topic of friends. I recommend that you read section 19.4; Friends is a classic C++ topic - something which is special to C++ in comparison with both Java and C#.

Chapter 20: This is the chapter about (single) inheritance. Section 20.2 describes the basis stuff - no surprises relative to similar languages. Section 20.3 is about virtuals, including Stroustrup's rational for having virtuals in an OOP language; No surprises. Section 20.3.4 introduces override control (including override and final, both new in C++11). Section 20.3.5.1 describes inhertance of constructors (also new in C++11), only useful in special circumstances, but interesting in relation to other OOPL. Section 20.4 about abstract classes is as expected, if you already are familiar with abstract classes (you probably are!) Section 20.5 about access control (private, protected, and public) is also standard OOP stuff; However, Stroustrup's advices and oppinions are interesting, and worthwhile. Skim this lightly. Section 20.6 is about pointer to memebers, a generalization of pointers to functions. It is interesting, but the notation is hard to deal with (strange). Read it if you care about this generalization.

Chapter 21 is about multiple inheritance in C++, and the programming techniques (and the philosophy) used for multiple inheritance. Section 21.2 is a large example, where several different designs are brought up. It is realatively easy to follow; Read it if you are interested in OOP design, rather than (just) the C++ programming language. Section 21.3 addreeses the technical issues involved in in multilple inheritance, such as ambiguities (21.3.3), repeated/shared base classs (virtual bases in C++ parleur). Notice the discussion of construction of virtual bases in 21.3.5.1, which is a little surprising. The last few pages of the chapter (from page 635) contain several complex scenarios, which takes some time to digest. You may prefer to skip those details, unless you really wish to concentrate you studies in the area of multiple inheritance.

In chapter 22 - Run-time type information- section 22.2 contains info and discussion about dynamic_cast (sligtly diffent for pointers (22.2.1) and for references (22.2.1.1)). Section 22.3 is about double dispatch and the visitor design pattern in C++ (drop unless you really love visitor). Section 22.5 is about the typeid operator (applicable on both type names and expressions). All taken together, chaper 22 is not a very important chapter from an AP part1 point of view.

Chapter 23: This is a long chapter about 'template basics'. In section 23.1 you will find an overview of chapter 23-29. The first part of chapter 23 is a good introduction to templates in C++. Section 23.2 introduces template-related concepts via an example, String<C>, where String now is a template (std::string is string of chars). Section 23.3 discusses the weak (and late) type checking of C++ programs that make use of templates. (A forthcoming solution to the problems is also presented!) Section 32.4 is a relatively long discussion of various kinds of members (data, function, statics, types, templates (= templates inside templates), friends) in class templates (most of which is natural generalizations of members in classes, with few exceptions). Please notice 'Member type aliases' in 23.4.3. Section 23.5 serves as an introduction to function templates. 23.5.1 is about the inference of function template arguments. The pages 687- 698 are rather technical - about specialized topics (including overloading of function templates and source code organization). Unless you have a special interest, you may skip this trailing part of chapter 23.

Chapter 24 is an introduction to generic programming in C++. It is recommended to skim through this chapter, because it conveys an intuitive idea about C++ generic programming. Section 24.2 advocates abstraction from a concrete function (lifting). Section 24.3 is about 'Concepts' - a set of constraints or requirements to template argments (not least types), and the handling of these constraints as compile-time predicates. Chapter 24 gives a possible direction for a future extension of C++, and as such it is an interesting chapter to read.

Chapter 25. The first section, 25.2, in this chapter is about the various kind of template parameters: types, values (int/pointers), functions, and templates). At the end of 25.2 the default template parameter mechanism is explained. 25.2 is a good section to read. Section 25.3 is the core of chapter 25 about user-defined template specialization. It explains how to have several definitions of a template, and how the compiler can chose the most appropriate one.

Previous reading guide     Next reading guide

/KN