May 2017
Intermediate to advanced
590 pages
17h 18m
English
When objects of types implementing the CRTP need to be stored homogeneously in a container, an additional idiom must be used. The base class template must be itself derived from another class with pure virtual functions (and a virtual public destructor). To exemplify this on the control class, the following changes are necessary:
class controlbase { public: virtual void draw() = 0; virtual ~controlbase() {} }; template <class T> class control : public controlbase { public: virtual void draw() override { static_cast<T*>(this)->erase_background(); static_cast<T*>(this)->paint(); } };
There are no changes required to the derived classes, such as button and checkbox. Then, we can store pointers to the abstract class in a container, ...
Read now
Unlock full access