📖 Book · cpp core · advanced
♻️ CRTP: Curiously Recurring Template Pattern
Static polymorphism with zero overhead — and the CRTP patterns interviewers ask about.
A deep dive on the Curiously Recurring Template Pattern: how a base templated on its own derived type achieves compile-time polymorphism with no vtable, the mechanics of the static_cast, the patterns you'll actually use (counter and comparison mixins, enable_shared_from_this, fluent builders, static interfaces), CRTP vs virtual dispatch, and the pitfalls (base-ctor dispatch, no common base type, the exact recurrence). Five runnable, verified demos.
5 chapters▶ runnable code✦ in-depth animation
▶ See it animated:CRTP: Static vs Dynamic Polymorphism →
What this book covers
- 01Why CRTP — polymorphism without a vtable
- 02The mechanics: the curious recurrence
- 03Patterns you'll actually use
- 04CRTP vs virtual — when to pick which
- 05Pitfalls & gotchas
Read it in full — runnable C++ + step-through animations
Every chapter of CRTP: Curiously Recurring Template Pattern ships complete, editable code you compile and run in the browser, plus the same in-depth animations as the lessons.