I am trying to use a CRTP base to store some static initialization code as follows:
template <typename T>
class InitCRTP
{
public:
static InitHelper<T> init;
};
template <typename T> InitHelper<T> InitCRTP<T>::init;
Now any class that needs to do the work in InitHelper<T>can do this:
class WantInit : public InitCRTP<WantInit>
{
public:
void dummy(){init;}
};
template class InitCRTP<WantInit>;
To create an instance InitCRTP<WantInit>::init, I can either use dummyor use an explicit instantiation, as shown above. Is there a way around this without doing either? I would like users of this template to simply inherit from InitCRTP<WantInit>and not worry about anything else. If this helps, use is C++11not a problem.
source
share