Question

I will post my code first then explain my issue:

typedef std::unique_ptr<SEntity> Entity;
typedef std::vector<Entity> EntityVector;
typedef std::map<std::string, EntityVector> EntityVectorMap;

const void pushEntityVector(const std::string& key, const EntityVector& entity_vector)
{
    m_entity_vector_map[key] = entity_vector;
}

As you can probably see, I'm trying to insert an EntityVector into the EntityVectorMap. I'm hit with this issue when I do this however:

c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_algobase.h|335|error: use of deleted function 'std::unique_ptr<_Tp, _Dp>& std::unique_ptr<_Tp, _Dp>::operator=(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = SE::SEntity; _Dp = std::default_delete<SE::SEntity>]'|

Thanks!

Was it helpful?

Solution

m_entity_vector_map[key] = entity_vector tries to copy an EntityVector thereby trying to copy an Entity which is essentially copying a std::unique_ptr. You cannot copy std::unique_ptr (it wouldn't be unique anymore).

You might want to move entity_vector into m_entity_vector_map, but then you cannot pass entity_vector as a const reference into pushEntityVector.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top