【发布时间】:2014-08-10 13:55:05
【问题描述】:
如果我们有
std::set<int > a;
std::vector<std::unordered_set<int>> b;
然后我们在b 中插入a
方法一:我们可以这样做:
std::set<int > a;
std::vector<std::unordered_set<int>> b (a.begin(), a.end());
方法2,我们不能这样做吗?
std::set<int > a;
std::vector<std::unordered_set<int>> b;
b.insert(a.begin(), a.end());
这个错误是什么意思?
错误 C2664: 'std::_Vector_iterator,std::equal_to<_kty>,std::allocator<_kty>>>>> std::vector,std::equal_to<_kty>,std::allocator<_kty>>,std::allocator<_ty>>::insert(std::_Vector_const_iterator,std::equal_to<_kty>,std::分配器<_kty>>>>,无符号 int,const _Ty &)' : 无法将参数 1 从 'std::_Tree_const_iterator>>' 到 'std::_Vector_const_iterator,std::equal_to<_kty>,std::allocator<_kty>>>>>' IntelliSense:没有重载函数实例“std::vector<_ty _alloc>::insert [with _Ty=std::unordered_set, std::equal_to, std::allocator>, _Alloc=std::allocator, std::equal_to, std::allocator>>]" 匹配参数列表 参数类型是: (std::_Tree_const_iterator>>, std::_Tree_const_iterator>>) 对象类型为:std::vector、std::equal_to、std::allocator>、 标准::分配器, std::equal_to, std::allocator>>>
如果我们需要将b 处理为全局unordered_set,解决方案是什么?
【问题讨论】:
-
我不太清楚您要做什么。你期待
b的内容是什么? -
错误表示
set不是unordered_set... -
错误消息中的哪些内容对您来说特别不清楚?
-
您不能将
b视为全局unordered_set,因为它不是一个集合。它是一个完整的集合向量。您的意思是在向量中添加a的内容吗,例如b[0].insert(...)?或者在向量中添加一个新集合,其中新集合的内容来自a? -
@Sandy:试试
b.emplace_back(a.begin(), a.end());
标签: c++