[英]Having trouble inserting values into a std::map with std::strings and std::vectors
我将首先发布我的代码,然后解释我的问题:
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;
}
您可能会看到,我正在尝试将EntityVector插入EntityVectorMap。 我这样做时却遇到了这个问题:
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>]'|
谢谢!
m_entity_vector_map[key] = entity_vector
尝试复制EntityVector
从而尝试复制实质上复制std::unique_ptr
的Entity
。 您不能复制std::unique_ptr
(不再是唯一的)。
您可能想将entity_vector
移到m_entity_vector_map
,但是随后您不能将entity_vector
作为const引用传递到pushEntityVector
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.