将 unordered_map 的新实例插入 unordered_map

Insert new instance of unordered_map into unordered_map

我有这些结构:

typedef std::unordered_set<std::string> functionSet;

typedef std::unordered_map<std::string, functionSet> classMap;

typedef std::unordered_map<std::string, classMap> semanticMap;

我有一个带有 class 个名称的映射,它包含带有函数名称的映射和带有变量的集合,我在我的代码中使用它进行语义分析。 当有一种情况,当定义了 new "class" 时,我正在调用将 new class 添加到 semnaticMap 的函数,所以这意味着它必须将键值对添加到 semanticMap,[= 的名称28=] 和 classMap 的新实例,但我不知道该怎么做。

我有一个可变的 semanticMap 地图。所以我尝试了 map.insert("name", new classMap), std::make_pair(),等等,但一切都显示

错误
No matching member function for call to 'insert'.

我要添加到 unordered_map "key" => new_unordered_map.

您的地图包含 classMap 类型作为值,而不是 classMap*(表达式 new classMap 的结果)。以下代码将为您工作:

map.insert({"name", classMap()});