将map<pair<int,int>,vector<Object> >添加到BST中,其中对是关键
Adding map<pair<int,int>,vector<Object> > into BST where pair is key
所以我有一张地图,其中键是月份和年份对,返回的值是矢量,它基本上是该月/年的天气实例向量。
注意:BST是由我制作的,而不是STL BST。
for (map<pair<int, int>, vector<Weather> >::iterator it = monthMap.begin(); it != monthMap.end(); ++it)
{
month = it->first.first;
year = it->first.second;
monthVec = it->second;
monthBST.Insert(map<make_pair(month,year),monthVec>);
}
但是,它返回了一堆错误,所有这些错误都与我如何在常量表达式中没有任何错误有关(make_pair,月,年,函数调用,月Vec)
main.cpp|170|error: 'std::make_pair(_T1, _T2)' cannot appear in a constant-expression|
main.cpp|170|error: 'month' cannot appear in a constant-expression|
main.cpp|170|error: 'year' cannot appear in a constant-expression|
main.cpp|170|error: a function call cannot appear in a constant-expression|
main.cpp|170|error: 'monthVec' cannot appear in a constant-expression|
main.cpp|170|error: template argument 1 is invalid|
main.cpp|170|error: template argument 2 is invalid|
main.cpp|170|error: template argument 3 is invalid|
main.cpp|170|error: template argument 4 is invalid|
我尝试了一堆东西,似乎想不通。
最终目标是拥有一个BST,它将自我平衡(因为数据已排序),并且找到键,它返回与其关联的monthVec。
根据您的代码,您似乎想要这样的东西:
typedef std::map<std::pair<int, int>, std::vector<Weather>> WeatherMap;
// for (const auto& itr : monthMap) // This is a bit cleaner
for (auto itr = monthMap.begin(); itr != monthMap.end(); ++it)
{
WeatherMap newMap;
newMap.insert(*itr);
monthBST.Insert(std::move(newMap));
}
鉴于您的解释,这没有多大意义,因此您可能实际上想要这样的东西:
typedef std::map<std::pair<int, int>, std::vector<Weather>> WeatherMap;
for (auto itr = monthMap.begin(); itr != monthMap.end(); ++it)
{
monthBST.Insert(*itr);
}
当您需要多个值作为键时,最好使用多映射。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- EASTL矢量<向量<int>>连续的
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 如何加入向量&lt; int&gt;到C 中的单个INT
- 是std :: set&lt; std :: future&gt;不可能存在
- 是numeric_limits&lt; int&gt; :: is_modulo从逻辑上矛盾
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改
- ///<评论></评论>在Visual Studio中