奇怪的问题
  • 板块学术版
  • 楼主Gcc_Gdb_7_8_1
  • 当前回复5
  • 已保存回复7
  • 发布时间2025/1/3 22:57
  • 上次更新2025/1/4 08:45:28
查看原帖
奇怪的问题
1058410
Gcc_Gdb_7_8_1楼主2025/1/3 22:57

rt,今天发现一个奇怪的问题,set<pair<int, int> > s 可以编译,但 unordered_set<pair<int, int> > s 却不可以。

unordered_set<pait<int, int> > 编译错误信息:

main.cc:32:36: error: use of deleted function ‘std::unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set() [with _Value = std::pair<int, int>; _Hash = std::hash<std::pair<int, int> >; _Pred = std::equal_to<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]’
   32 |     unordered_set<pair<int, int> > s;
      |                                    ^
In file included from /opt/rh/devtoolset-9/root/usr/include/c++/9/unordered_set:47,
                 from /opt/rh/devtoolset-9/root/usr/include/c++/9/x86_64-redhat-linux/bits/stdc++.h:118,
                 from main.cc:1:
/opt/rh/devtoolset-9/root/usr/include/c++/9/bits/unordered_set.h:135:7: note: ‘std::unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set() [with _Value = std::pair<int, int>; _Hash = std::hash<std::pair<int, int> >; _Pred = std::equal_to<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]’ is implicitly deleted because the default definition would be ill-formed:
  135 |       unordered_set() = default;

如何解决?

2025/1/3 22:57
加载中...