记录详情

Compile Error

/in/foo.cc: In function 'int main()':
/in/foo.cc:34:19: error: passing 'const Counter' as 'this' argument discards qualifiers [-fpermissive]
   34 |         it->output();
      |         ~~~~~~~~~~^~
/in/foo.cc:15:10: note:   in call to 'void Counter::output()'
   15 |     void output() { cout << val << " " << cnt << endl; }
      |          ^~~~~~
In file included from /usr/include/c++/12/string:48,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/iostream:39,
                 from /in/foo.cc:1:
/usr/include/c++/12/bits/stl_function.h: In instantiation of 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Counter]':
/usr/include/c++/12/bits/stl_tree.h:2533:33:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::find(const _Key&) [with _Key = Counter; _Val = Counter; _KeyOfValue = std::_Identity<Counter>; _Compare = std::less<Counter>; _Alloc = std::allocator<Counter>; iterator = std::_Rb_tree<Counter, Counter, std::_Identity<Counter>, std::less<Counter>, std::allocator<Counter> >::iterator]'
/usr/include/c++/12/bits/stl_set.h:795:25:   required from 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::find(const key_type&) [with _Key = Counter; _Compare = std::less<Counter>; _Alloc = std::allocator<Counter>; iterator = std::_Rb_tree<Counter, Counter, std::_Identity<Counter>, std::less<Counter>, std::allocator<Counter> >::const_iterator; key_type = Counter]'
/in/foo.cc:27:43:   required from here
/usr/include/c++/12/bits/stl_function.h:408:20: error: no match for 'operator<' (operand types are 'const Counter' and 'const Counter')
  408 |       { return __x < __y; }
      |                ~~~~^~~~~
/in/foo.cc:12:10: note: candidate: 'bool Counter::operator<(const Counter&)' (near match)
   12 |     bool operator<(const Counter &other) { return val < other.val; }
      |          ^~~~~~~~
/in/foo.cc:12:10: note:   passing 'const Counter*' as 'this' argument discards qualifiers
In file included from /usr/include/c++/12/string:47:
/usr/include/c++/12/bits/stl_iterator.h:451:5: note: candidate: 'template<class _Iterator> bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  451 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/12/bits/stl_iterator.h:451:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12/bits/stl_function.h:408:20: note:   'const Counter' is not derived from 'const std::reverse_iterator<_Iterator>'
  408 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/12/bits/stl_iterator.h:496:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  496 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/12/bits/stl_iterator.h:496:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12/bits/stl_function.h:408:20: note:   'const Counter' is not derived from 'const std::reverse_iterator<_Iterator>'
  408 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/12/bits/stl_iterator.h:1683:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1683 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/12/bits/stl_iterator.h:1683:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12/bits/stl_function.h:408:20: note:   'const Counter' is not derived from 'const std::move_iterator<_IteratorL>'
  408 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/12/bits/stl_iterator.h:1748:5: note: candidate: 'template<class _Iterator> bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1748 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/12/bits/stl_iterator.h:1748:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12/bits/stl_function.h:408:20: note:   'const Counter' is not derived from 'const std::move_iterator<_IteratorL>'
  408 |       { return __x < __y; }
      |                ~~~~^~~~~

信息

递交者
类型
自测
语言
C++
递交时间
2025-05-24 23:55:31
评测时间
2025-05-24 23:55:31
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes