11.x — Chapter 11 summary and where to go next
Quick review#
- Templates let one piece of code work with many types.
<algorithm>has ready-made tools:sort,find,count, and more. Lambdas are tiny on-the-spot functions.- Inheritance builds a class on top of another.
virtual+overridelet each child behave its own way. throw,tryandcatchhandle errors.std::ifstreamandstd::ofstreamread and write files.
Pick an answer. You find out right away if it is right.
What does template <typename T> let you do?
T is a placeholder. C++ fills in the real type when you use it.
What does std::sort(v.begin(), v.end()) do?
It sorts the vector itself, smallest first.
Where does code go that might throw an exception?
try holds the risky code. catch handles the problem if something is thrown.
Write a template function swapIfBigger(T& a, T& b) that swaps a and b only if a is bigger than b.
template <typename T>void swapIfBigger(T& a, T& b){ if (a > b) std::swap(a, b);}Sort a std::vector<std::string> by length, shortest first, using std::sort and a lambda.
std::sort(words.begin(), words.end(), [](const std::string& a, const std::string& b) { return a.length() < b.length(); });What next?#
You now know the core of C++. Here are good next steps:
- Build something! A text adventure, a to-do list saved to a file, a quiz game, a tiny bank system.
- Carry on to chapter 12 for power tools and two full projects.
- Re-read the chapters that felt hard. They'll make more sense now.
- Keep the cheat sheet open while you code.
- Try a graphics library like SFML or raylib to make simple games.
Nobody learns programming by reading alone. Pick a small project and write it, one box at a time. You've got this! 🚀
Tip: press ← / → to move between lessons, / to search.