Search⌘ K
AI Features

CRTP

Explore the Curiously Recurring Template Pattern (CRTP) in C++ to understand its use for static polymorphism and mixins. Discover how CRTP allows compile-time method dispatch and how it helps add reusable behavior to classes without runtime overhead.

We'll cover the following...

CRTP

The acronym CRTP stands for the C++ idiom Curiously Recurring Template Pattern and is a technique in C++ in which a Derived class derives from a class template Base. The key is that Base has Derived as a template argument.

Let’s have a look at an example:

template<class T> 
class Base{
   ...
};

class Derived:
...