0

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!

1
  • 1
    You're inserting a copy of entity_vector. That won't work as the elements are unique_ptrs, i.e. noncopyable, therefore the vector itself is noncopyable. Commented Jan 12, 2014 at 19:21

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.