DEV Community

Discussion on: Factory With Self-Registering Types

Collapse
 
morgoth990 profile image
morgoth990 • Edited

In C++17 you can declare s_bRegistered inline:

template <typename T>
class RegisteredInFactory
{
protected:
    inline static bool s_bRegistered;
}

template <typename T> 
bool RegisteredInFactory<T>::s_bRegistered = EngineObjectFactory::Register(T::GetFactoryName(), T::CreateMethod);

avoiding ODR-use check without workarounds in the derived class