I'm making a component-entity system for a game.
I have a class, Object, which is just a shell to hold components, which in turn are stored in the object in a std::map as a (typeid, unique_ptr<>) pair. Each component is a class derived from Component.
The Object class has several template functions (the class itself is not a template though) to facilitate access and modification to the components. The template definitions are in the header file with the class definition (to avoid linker errors).
When compiling, I receive the following error (in VS2012):
error C2664: 'std::unique_ptr<_Ty,_Dx>::unique_ptr(std::nullptr_t) throw()' : cannot convert parameter 1 from 'std::unique_ptr<_Ty>' to 'std::nullptr_t'
with
[
_Ty=Positional,
_Dx=std::default_delete<Positional>
]
and
[
_Ty=Component
]
nullptr can only be converted to pointer or handle types
see reference to function template instantiation 'std::unique_ptr<_Ty,_Dx> Object::__GetComponent<Positional>(void)' being compiled
with
[
_Ty=Positional,
_Dx=std::default_delete<Positional>
]
in reference to the following function:
template <typename T> std::unique_ptr<T>
Object::__GetComponent()
{
if(m_components.count(&typeid(T)) != 0)
{
return m_components[&typeid(T)];
}
else
{
return std::unique_ptr<T>(new T);
}
}
What is going on here? No where in my code do I use a custom deleter, nor do I try to store a nullptr in a unique_ptr instance. I guess more specifically, what is trying to cause the conversion from unique_ptr<> to nullptr_t?
I also receive this error for every component, not just the 'Positional' one listed.