Templates: CRTP

In this lesson, we will learn about curiously recurring template patterns in modern C++.

We'll cover the following

CRTP

The acronym CRTP stands for the C++ idiom Curiously Recurring Template Pattern. CRTP is a technique in Modern 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: public Base<Derived>{ 
   ...
};

CRTP enables static polymorphism.

Get hands-on with 1400+ tech skills courses.