I have a base class:
template <typename T>
class Base
{
public:
struct RegisterType {
RegisterType() { RegisterHelper::get().registerType<T>();}
};
static RegisterType s_register;
};
template <typename T>
typename Base<T>::RegisterType Base<T>::s_register __attribute__((used));
and a derived class:
class Derived : public Base<Derived>
{
public:
constexpr static const char *const propertyA = "propertyA";
...
}
Derived types need to be registered in order to map some properties to derived type id and, therefore, make a cleaner data driven loader. However, I don't want to explicitly register them in an outer class, so my target is that Derived type registration is inside Derived type definition.
The problem I found is that there are some Derived classes that are not used in the project code and, in consequence, those derived classes are not registered, which lead to incomplete final result in loader. This is fixed if I explicitly include the Derived type in question(i. e. DerivedOne), such as: '#include "DerivedOne.h"'
Is there any way to force its initialization without having to explicitly include all derived classes?
Thanks in advance