The C++ Programming Language (2021-07-12 - 2021-07-16)

Day 1

Setup for the new kids

Recapitulate some C

Group project review

Jump into C++


On Github, there is a directory OO-Point. Starting from the point implementation, write comparable classes

  • circle, containing a method circle::area()

  • rect, also containing a method circle::area()

  • sphere (in 2D :-) ), also containing a method circle::area()

Make the associated test programs run:


Day 2

Regular Topics


  • point::operator==()

  • rect::operator+=()

  • static double point::distance(const point&, const point&)

Day 3


Finish exercises from day 2

Regular Topics

Toolchain: C/C++ Build (How Complicated Can Things Be?)


Trying to get #include dependencies right. Respectively, what you’re up to when you want to write a Makefile (or more of those) by hand.


Using CMake to do manage the build. What is still left to the developer is to define “module” dependencies.

Exercises: Using the C++ Toolbox

Day 4

Finish First “User Database” Functionality

  • UserDB::has_lastname(), using std::find_if()

Unit Testing

Current state is, we’re writing one program to test one aspect/requirement. This is something that can be formalized (/me big fan of things that are so simple).

Install Google’s unittesting framework (on Doze, sadly), and start to use it.

GTest Installation

Clone GitHub repository:

$ git clone


  • Build with VS Code: open directory, and hit CMake build botton

  • Build by hand

$ cd googletest
$ cmake .


  • Copy lib/*.a to MinGW installation ..../lib directory

  • Copy include/gtest/ to MinGW installation ..../include directory

Git Workflows

Central workflow. Much like SVN’s, except that local commits are possible.


Distributed workflow. (At least, one possibility). Resembles Github “pull requests”.



  • Torture them with even more requirements that they need to implement

Regular Topics

Day 5

  • References recap (References)

  • explicit: another C++ trap/bug (automatic conversion), fixed by an ad-hoc solution - the explicit keyword, bolted onto what’s there. Here’s a live-hacked explanation of it.

    It has gotten a bit larger becauser I used it as an introduction to recource management and smart pointers.

  • Pointer classes (“smart pointers”)

    • std::unique_ptr

      Although std::unique_ptr<> is the simpler of the two in what it does, its usage is more involved. Ownership transfer (this is what I like about it) is implemented using the outright genius “move” mechanism (since C++11), and one needs to know a bit when the compiler fails to enforce the ownership transfer contract.

      Live-hacked that here.

    • std::shared_ptr

      Didn’t go through it in great detail (time was over anyway). Shared ownership, though, is easier explained than unique ownership: “just don’t think about it”. (Should have mentioned reference cycles, to make things more complicated :-) ).

Day X

Smart Pointers, Recap


OO, and Polymorphism