As already pointed out by PeterT, this is the curiously recurring template pattern (CRTP).
It is a way to implement static polymorphism in C++ as the base class A
has knowledge about the subclass B
and its (internal) types and states.
For instance, the logic in A
can return objects of the right type which would not be possible with dynamic polymorphism. CRTP allows to move that logic to the base class where dynamic polymorphism would require virtual functions within the derived class to deal with the right type appropriate to B
.
A more detailed explanation is given here.