Explains the Curiously Recurring Template Pattern (CRTP) in C++ as an alternative to virtual functions for achieving polymorphism at compile time. Using an Animal/Dog/Cat example, it demonstrates how a base class template can call methods on its derived type via a static cast of `this`, eliminating vtable overhead. Covers trade-offs: CRTP avoids vtable pointer size growth and double pointer indirection at the cost of losing runtime dispatch and producing distinct types per instantiation.

4m read timeFrom galowicz.de
Post cover image
Table of contents
The examplePROs and CONs

Sort: