dimanche 25 juin 2017

Generic Factory pattern Implementation

I am trying to implement a template factory pattern.

template <typename T1, typename T2>
class SpawnManager
{
public:
        static bool registerit(const T1& type, std::unique_ptr<T2>(*f)(const sf::Vector2f & pos));
        static std::unique_ptr<T2> create(const T1& type, const sf::Vector2f& pos);

private:
        static std::map<T1, std::unique_ptr<T2>(*)(const sf::Vector2f& pos)> m_map;
};
//the problem is here!
template <typename T1, typename T2>
std::map<T1, std::unique_ptr<T2>(*)(const sf::Vector2f& pos)> SpawnManager<T1, T2>::m_map = std::map<T1, std::unique_ptr<T2>(*)(const sf::Vector2f& pos)>{};

This code complies fine, but it fails at running time..

Exception thrown: read access violation. std::_Tree > (__cdecl*)(sf::Vector2 const &),std::less,std::allocator > (__cdecl*)(sf::Vector2 const &)> >,0> >::_Root(...) returned 0x4.

Aucun commentaire:

Enregistrer un commentaire