vendredi 2 juillet 2021

Casting std::shared_ptr

I have a base class and a templated derived class as below

class ComponentArray_Base
{
 public:
     virtual ~ComponentArray_Base() = default;              
     virtual void EntityDestroyed(Entity entity) = 0;       
};


template <typename cType>
class ComponentArray : public ComponentArray_Base
{
 //Derived class implementation...
}

and later in the code, outside of the two classes I attempt to add the derived class to an unordered map with

mComponentArrays.insert({ TypeName, std::make_shared<ComponentArray<cType>> });

which gives me the error

C:\Users\davis\source\repos\ECS\ECS\Component.h(91,1): error C2664: 'void std::_Hash<std::_Umap_traits<_Kty,_Ty,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::insert(std::initializer_list<std::pair<const char *const ,std::shared_ptr<ComponentArray_Base>>>)': cannot convert argument 1 from 'initializer list' to 'std::initializer_list<_Ty>'
1>        with
1>        [
1>            _Kty=const char *,
1>            _Ty=std::shared_ptr<ComponentArray_Base>,
1>            _Hasher=std::hash<const char *>,
1>            _Keyeq=std::equal_to<const char *>,
1>            _Alloc=std::allocator<std::pair<const char *const ,std::shared_ptr<ComponentArray_Base>>>
1>        ]
1>        and
1>        [
1>            _Ty=std::pair<const char *const ,std::shared_ptr<ComponentArray_Base>>
1>        ]

I do not seem to be having this problem when using a raw pointer and cannot figure out what the problem is as the hash function should be defined for const char*

Aucun commentaire:

Enregistrer un commentaire