簡體   English   中英

使用std :: strings和std :: vectors將值插入std :: map時遇到麻煩

[英]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_ptrEntity 您不能復制std::unique_ptr (不再是唯一的)。

您可能想將entity_vector移到m_entity_vector_map ,但是隨后您不能將entity_vector作為const引用傳遞到pushEntityVector

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM