我一直在尝试实现一个由自定义数据类型和自定义比较器组成的优先级队列,但是当我尝试编译时,我得到了这个错误。我尝试了多个声明,但它们都会产生这个错误。
priority_queue<myData, vector<myData>, myComp> myPQ;
priority_queue<myData, vector<myData>, myComp> myPQ(compVariable);
我也在尝试创建这些优先级队列的向量。
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h: In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Order]’:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_heap.h:183:47: required from ‘void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Order*, std::vector<Order, std::allocator<Order> > >; _Distance = long int; _Tp = Order; _Compare = std::less<Order>]’
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_heap.h:222:58: required from ‘void std::push_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Order*, std::vector<Order, std::allocator<Order> > >; _Compare = std::less<Order>]’
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_queue.h:499:41: required from ‘void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = Order; _Sequence = std::vector<Order, std::allocator<Order> >; _Compare = std::less<Order>; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = Order]’
Market.cpp:144:32: required from here
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: error: no match for ‘operator<’ (operand types are ‘const Order’ and ‘const Order’)
{ return __x < __y; }
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: candidates are:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:64:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_pair.h:220:5: note: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_pair.h:220:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::pair<_T1, _T2>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:297:5: note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator<(const reverse_iterator<_Iterator>& __x,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:297:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:347:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator<(const reverse_iterator<_IteratorL>& __x,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:347:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:1055:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator<(const move_iterator<_IteratorL>& __x,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:1055:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:1061:5: note: template<class _Iterator> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator<(const move_iterator<_Iterator>& __x,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_iterator.h:1061:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:52:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/basic_string.h:2569:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/basic_string.h:2569:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:52:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/basic_string.h:2581:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/basic_string.h:2581:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:52:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/basic_string.h:2593:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const _CharT* __lhs,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/basic_string.h:2593:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: mismatched types ‘const _CharT*’ and ‘Order’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/vector:64:0,
from P2.h:4,
from Market.cpp:3:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_vector.h:1420:5: note: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_vector.h:1420:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::vector<_Tp, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/deque:64:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/queue:60,
from Market.cpp:6:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:273:5: note: template<class _Tp, class _Ref, class _Ptr> bool std::operator<(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _Ref, _Ptr>&)
operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:273:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/deque:64:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/queue:60,
from Market.cpp:6:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:281:5: note: template<class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> bool std::operator<(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _RefR, _PtrR>&)
operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:281:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/deque:64:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/queue:60,
from Market.cpp:6:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:1975:5: note: template<class _Tp, class _Alloc> bool std::operator<(const std::deque<_Tp, _Alloc>&, const std::deque<_Tp, _Alloc>&)
operator<(const deque<_Tp, _Alloc>& __x,
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_deque.h:1975:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::deque<_Tp, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/queue:64:0,
from Market.cpp:6:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_queue.h:286:5: note: template<class _Tp, class _Seq> bool std::operator<(const std::queue<_Tp, _Seq>&, const std::queue<_Tp, _Seq>&)
operator<(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y)
^
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_queue.h:286:5: note: template argument deduction/substitution failed:
In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/string:48:0,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ios:42,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/ostream:38,
from /usr/um/gcc-4.8.2/include/c++/4.8.2/iostream:39,
from Market.cpp:1:
/usr/um/gcc-4.8.2/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const Order’ is not derived from ‘const std::queue<_Tp, _Seq>’
{ return __x < __y; }
以下是导致错误的原因示例:
class myData {
public:
int a;
int b;
int c;
int d;
};
class myComp {
public:
bool operator()(myData& d1, myData& d2) {
if(d1.a == d2.a) {
return d2.b < d2.c;
}
else {
return d1.a < d2.a;
}
}
};
priority_queue<myData, vector<myData>, myComp> myPQ;
vector<priority_queue<myData, vector<myData>, myComp> > vec_PQ(n, myPQ);
答案 0 :(得分:0)
来自:http://en.cppreference.com/w/cpp/concept/Compare
概念比较是用户提供的函数对象类型中某些标准库工具所需的一组要求。
当上下文转换为
bool
时,应用于Compare类型对象的函数调用操作的返回值,如果调用的第一个参数出现在true >此比较类型引起的严格弱排序关系,否则为false
。与任何BinaryPredicate一样,不允许对该表达式的求值调用解除引用的迭代器的非const成员函数。
myComp::operator()
的论据应为const&
。
bool myComp::operator()(myData const& d1, myData const& d2) {
如@ T.C所示。在注释中,函数本身应该是const成员函数,但在这种情况下严格来说不是必需的。