我努力學習如何std::map
的作品,我有以下問題的結構:映射的int在C++載體
int id; // stores some id
struct stuff {
std::vector<int> As;
std::vector<int> Bs;
} stuff;
std::map<int, stuff> smap;
void foo() {
int count = 2;
int foo_id = 43;
for (int i = 0; i < count; count++) {
stuff.As.push_back(count);
stuff.Bs.push_back(count);
}
smap.insert(foo_id, stuff);
}
目前我得到:
error: type/value mismatch at argument 2 in template parameter list for ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’
std::map<int, stuff> smap;
error: request for member ‘insert’ in ‘smap’, which is of non-class type ‘int’
smap.insert(int, stuff);
我想成爲能夠將id
映射到由兩個向量構成的struct
,該向量被填充到for循環中。我究竟做錯了什麼?或者有更好的方法來映射這個?
嘗試重命名的2'stuff' – JVApen