[英]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.