嗨,我正在尝试将集合的特定节点添加到列表中,该列表位于哈希表中
Hi, I am trying to add specific nodes of a set to a list, the list being in a hash table
我有以下集合和列表声明:
set<mystruct> my_entries;
unordered_map<string, list<_Rb_tree_const_iterator<mystruct>>> mylist;
我正在尝试做的基本上是在将集合的一些特定节点插入到集合中后将其插入到列表中。
auto inserted = my_entries.insert(entry);
mylist[name].push_back(*inserted.first);
我收到以下错误:
error: no matching function for call to
'std::list<std::_Rb_tree_const_iterator<mystruct> >::push_back(const
mystruct&)’
mylist[name].push_back(*inserted.first);
note: no known conversion for argument 1 from 'const mylist’ to
'std::list<std::_Rb_tree_const_iterator<mylist> >::value_type&& {aka
std::_Rb_tree_const_iterator<mylist>&&}'
知道出了什么问题吗?
谢谢。
如注释所述,不应尝试使用标准库中的内部类型。 您可以按如下方式存储迭代器:
set<mystruct> my_entries;
unordered_map<string, list<set<mystruct>::const_iterator>> mylist;
// ...
mylist[name].push_back(inserted.first);
每当存储迭代器时,了解管理此类迭代器何时变得无效的规则非常重要。 在 std::set::insert 的情况下,您可以保证:
没有迭代器或引用失效。
相关文章:
- C 指针节点帮助 - 将参数复制到链接的列表节点更改该节点的不同部分
- 是否可以将新的列表节点分配给链表的现有节点
- 我如何不调用位于链接列表节点中的对象的构造函数
- 链接列表节点的访问违规:C
- 将指针分配给链接列表节点会引发"Segmentation Fault"
- C 链接列表节点与类
- 错误 - 列表节点未命名类型
- 在模板类列表/节点程序中获取错误
- 如何为链接列表节点定义一个以指针为模板类型的模板类
- 链接列表节点的RAII样式C++类
- 存储链接列表节点地址
- 泛型列表节点类中出错
- 获取列表<节点*>中的字符并返回
- 错误 C2440:"=":无法从"列表节点 *"<T>转换为"列表节点<T> *"
- 通过池分配器中的内存地址访问可用列表节点时出现问题
- 无法在赋值中将"列表节点**"转换为"列表节点*"
- c++ STL列表节点内存分配中的段错误
- vector std::out_of_range 在我自己的模板类中(指向列表节点的指针向量),但我不明白为什么
- 列表节点指针"未在此范围内声明"?
- GCC 列表节点交换实现过于复杂