C++ Foundations
What the closing brace runs
In C++ nothing decides for you. No collector notices the buffer, no checker refuses the second owner, and the compiler will write you a copy that frees one allocation twice. So learn to read a class and say what its destructor promises — then write one whose promise holds on every path out, and compile it yourself.
- Modules
- 5
- Drills
- 8
- Build steps
- 5
- Time
- ~4h
Walk out with
A C++ file on your own machine holding a class that owns a heap buffer, releases it on every path out of a scope, and stays correct when it is copied.
What you build up to
References and lifetimes
Whether the call copied it, and whether a name outlives it.
Constructors that hold
Two phases, declaration order, and the invariant.
Destructors and copies
What the brace runs, and the three that travel together.
Const and templates
The write it forbids, and what T comes out as.
The pitch
What you practise, and what you leave with
One C++ file: a class that owns a heap buffer, frees it on every path out, survives being copied, and ends up holding any type you ask it for.
You will practise
- Say what a call did to your object
- Find the reference that outlives it
- Count what the closing brace runs
- Name the write const forbids
Afterwards you can
- Compile and run C++ yourself
- Write a destructor that cannot be skipped
- Decide if a class needs the Rule of Three
- Explain where a template error came from
Modules
5 modules, 30 items
Lessons explain one idea. Drills repeat it until it sticks. Build steps make something that exists afterwards.
- 1
Bind a name, not a copy
~38 minSay whether a call sees your object or a copy, and whether a reference outlives it.
- LessonWhat you are about to build4 min
- LessonGive one object a second name10 min
- DrillSay what the call does to your object8 min
- LessonA name outliving its object5 min
- DrillFind the reference that outlives it11 min
- 2
Build a class that cannot be wrong
~23 minWrite a constructor that initialises every member once, in the right order.
- LessonInitialise a member, do not assign it8 min
- LessonWhy the constructor is the only way in6 min
- DrillWork out what the constructor really did9 min
- 3
Make the destructor the promise
~2hWrite a class that releases what it owns on every path out, and survives being copied.
- LessonSay what a closing brace runs8 min
- LessonTie the release to the brace5 min
- LessonThe objects no brace can reach4 min
- DrillCount the destructor runs10 min
- LessonSee what a default copy does8 min
- LessonThree that travel together7 min
- LessonThe better answer, most of the time5 min
- DrillJudge what the compiler wrote for you11 min
- Build stepAdd a destructor that frees the buffer18 min
- Build stepGive the copy a buffer of its own14 min
- Build stepAssign onto a tally that owns a buffer13 min
- 4
Say what you will not change
~40 minRead const in any declaration and name the exact write it forbids.
- LessonRead const right to left7 min
- LessonPromise it about the whole object5 min
- LessonWhat const does not promise5 min
- DrillPick the line const refuses9 min
- Build stepMake the tally const-correct14 min
- 5
Write it once, for every type
~58 minWrite a template, say what T deduces to, and read an error from an instantiation.
- LessonLet the compiler write the overloads8 min
- LessonOne ampersand, two answers4 min
- LessonWhy the error names another line5 min
- DrillWork out what T comes out as9 min
- DrillWrite the line from memory10 min
- Build stepTally anything, on two types at once22 min
More in Languages
Keep going
Python Foundations
Read a program before you run it. Then write one worth showing.
Foundational~6h8 modules
Python Fluency
Choose the shape before you type. Then say it in one line.
Intermediate~5h7 modules
Python Confidence
Somebody else wrote it. Find out whether it works.
Advanced~7h7 modules
Python Craft
It works. Now make it somebody else's.
Advanced~10h7 modules
Know what the closing brace runs.
The first item is free. ~4h of focused work, at your own pace.
Advanced~4h5 modules