Tutorial by Examples: crtp

CRTP is a powerful, static alternative to virtual functions and traditional inheritance that can be used to give types properties at compile time. It works by having a base class template which takes, as one of its template parameters, the derived class. This permits it to legally perform a static_c...
The example in Visitor Pattern provides a compelling use-case for CRTP: struct IShape { virtual ~IShape() = default; virtual void accept(IShapeVisitor&) const = 0; }; struct Circle : IShape { // ... // Each shape has to implement this method the same way ...

Page 1 of 1