这是程序
#include <iostream>
#include <set>
using namespace std;
class Rectangle {
int h, w;
int AllLen, Area;
public:
Rectangle(int a, int b) :h(a), w(b) {
AllLen = (a + b) * 2;
Area = a * b; }
friend bool operator < (const Rectangle& a, const Rectangle& b) {
if (a.Area == b.Area)
return a.AllLen > b.AllLen;
return a.Area > b.Area; }
friend class Comp;
friend ostream& operator <<(ostream& os, const Rectangle& x) {
os << x.Area << " " << x.AllLen; return os; }
};
class Comp {
public:
bool operator()(const Rectangle& a, const Rectangle& b) {
if (a.AllLen == b.AllLen)
return a.Area < b.Area;
return a.AllLen < b.AllLen; }
};
int main() {
multiset<Rectangle> m1;
multiset<Rectangle, Comp> m2;
int n, a, b;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
m1.insert(Rectangle(a, b));
m2.insert(Rectangle(a, b)); }
for (multiset<Rectangle>::iterator it = m1.begin(); it != m1.end(); it++) { cout << *it << endl; } cout << endl;
for (multiset<Rectangle>::iterator it = m2.begin(); it != m2.end(); it++) { cout << *it << endl; } return 0;}
出错是
In file included from /usr/include/c++/9/set:60, from /home/runner/temp/33171727.22293/Main.cc:2:/usr/include/c++/9/bits/stl_tree.h: In instantiation of ‘static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type) [with _Key = Rectangle; _Val = Rectangle; _KeyOfValue = std::_Identity<Rectangle>; _Compare = Comp; _Alloc = std::allocator<Rectangle>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type = const std::_Rb_tree_node<Rectangle>*]’:/usr/include/c++/9/bits/stl_tree.h:2126:44: required from ‘std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_equal_pos(const key_type&) [with _Key = Rectangle; _Val = Rectangle; _KeyOfValue = std::_Identity<Rectangle>; _Compare = Comp; _Alloc = std::allocator<Rectangle>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = Rectangle]’/usr/include/c++/9/bits/stl_tree.h:2175:4: required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_equal(_Arg&&) [with _Arg = Rectangle; _Key = Rectangle; _Val = Rectangle; _KeyOfValue = std::_Identity<Rectangle>; _Compare = Comp; _Alloc = std::allocator<Rectangle>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<Rectangle>]’/usr/include/c++/9/bits/stl_multiset.h:508:51: required from ‘std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = Rectangle; _Compare = Comp; _Alloc = std::allocator<Rectangle>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<Rectangle>; std::multiset<_Key, _Compare, _Alloc>::value_type = Rectangle]’/home/runner/temp/33171727.22293/Main.cc:36:34: required from here/usr/include/c++/9/bits/stl_
下载码来一个