April 2017
Beginner to intermediate
394 pages
9h 16m
English
Those worried about writing a lot of little classes are in luck. Most, if not all, of our builders will be the same except for the specific derived class they instantiate. That means we can use the power of C++ templates to create builders for us. Our templated builder will look like this:
//M5StageBuilder.h template <typename T> class M5StageTBuilder : public M5StageBuilder { public: virtual M5Stage* Build(void); }; template <typename T> M5Stage* M5StageTBuilder<T>::Build(void) { return new T(); }
This code works great for most of our stages. The only time it doesn't work is when we need to do something more specific, such as call a non-default constructor, or a function specific to the derived stage.
Notice that ...
Read now
Unlock full access