【发布时间】:2020-10-23 22:40:54
【问题描述】:
我需要浏览一个地图并获得一组条目,我必须在下一次迭代之前删除这些条目。我正在尝试使用 unordered_set 迭代器将迭代器存储到这些条目。
unordered_set < map<int,int>::iterator > todel;
我收到以下超级奇怪且冗长的错误。
谁能告诉我发生了什么以及如何纠正它?
Line 22: Char 50: fatal error: call to implicitly-deleted default constructor of 'unordered_set<map<int, int>::iterator>' (aka 'unordered_set<_Rb_tree_iterator<std::pair<const int, int> > >')
unordered_set < map<int,int>::iterator > todel;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/unordered_set.h:135:7: note: explicitly defaulted function was implicitly deleted here
unordered_set() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/unordered_set.h:100:18: note: default constructor of 'unordered_set<std::_Rb_tree_iterator<std::pair<const int, int> >, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::equal_to<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::allocator<std::_Rb_tree_iterator<std::pair<const int, int> > > >' is implicitly deleted because field '_M_h' has a deleted default constructor
_Hashtable _M_h;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable.h:408:7: note: explicitly defaulted function was implicitly deleted here
_Hashtable() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable.h:174:7: note: default constructor of '_Hashtable<std::_Rb_tree_iterator<std::pair<const int, int> >, std::_Rb_tree_iterator<std::pair<const int, int> >, std::allocator<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Identity, std::equal_to<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, true, true> >' is implicitly deleted because base class '__detail::_Hashtable_base<_Rb_tree_iterator<pair<const int, int> >, _Rb_tree_iterator<pair<const int, int> >, _Identity, equal_to<_Rb_tree_iterator<pair<const int, int> > >, hash<_Rb_tree_iterator<pair<const int, int> > >, _Mod_range_hashing, _Default_ranged_hash, _Hashtable_traits<true, true, true> >' has a deleted default constructor
: public __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1824:5: note: explicitly defaulted function was implicitly deleted here
_Hashtable_base() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1773:5: note: default constructor of '_Hashtable_base<std::_Rb_tree_iterator<std::pair<const int, int> >, std::_Rb_tree_iterator<std::pair<const int, int> >, std::__detail::_Identity, std::equal_to<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, true, true> >' is implicitly deleted because base class '_Hash_code_base<std::_Rb_tree_iterator<std::pair<const int, int> >, std::_Rb_tree_iterator<std::pair<const int, int> >, std::__detail::_Identity, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, _Hashtable_traits<true, true, true>::__hash_cached::value>' has a deleted default constructor
: public _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1379:7: note: explicitly defaulted function was implicitly deleted here
_Hash_code_base() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1355:7: note: default constructor of '_Hash_code_base<std::_Rb_tree_iterator<std::pair<const int, int> >, std::_Rb_tree_iterator<std::pair<const int, int> >, std::__detail::_Identity, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>' is implicitly deleted because base class '_Hashtable_ebo_helper<1, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > > >' has a deleted default constructor
private _Hashtable_ebo_helper<1, _H1>,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1106:7: note: explicitly defaulted function was implicitly deleted here
_Hashtable_ebo_helper() = default;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/hashtable_policy.h:1104:7: note: default constructor of '_Hashtable_ebo_helper<1, std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >, true>' is implicitly deleted because base class 'std::hash<std::_Rb_tree_iterator<std::pair<const int, int> > >' has a deleted default constructor
: private _Tp
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/functional_hash.h:101:19: note: default constructor of 'hash<std::_Rb_tree_iterator<std::pair<const int, int> > >' is implicitly deleted because base class '__hash_enum<std::_Rb_tree_iterator<std::pair<const int, int> > >' has no default constructor
struct hash : __hash_enum<_Tp>
^
1 error generated.
【问题讨论】:
-
如何散列一个迭代器?
unordered_set需要 hash function 用于您要存储的类型。
标签: c++ c++11 iterator unordered-set