September 2017
Beginner to intermediate
384 pages
9h 18m
English
You may already have noticed, but especially after seeing the preceding code sample it should be apparent, that whenever you inherit from enable_shared_from_this the name of your class always appears in the template parameter list of its own base class! This pattern of "X inherits from A<X>" is known as the Curiously Recurring Template Pattern, or CRTP for short. It's common whenever some aspect of the base class depends on its derived class. For example, in our case the name of the derived class is incorporated into the return type of the shared_from_this method.
Another common case where the CRTP is warranted is when some behavior of the derived class is incorporated into the behavior provided by ...
Read now
Unlock full access