std::map使用结构体自定义键值

使用STL中的map时候,有时候需要使用结构题自定义键值,比如想统计点的坐标出现的次数

struct Node{
    int x,y;
};

......

map<Node,int>mp;
mp[(Node){x,y}]++;

  这样子的话,会出现一堆报错

c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h||In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Node]‘:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_map.h|483|required from ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = Node; _Tp = int; _Compare = std::less<Node>; _Alloc = std::allocator<std::pair<const Node, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = Node]‘|
E:\Programming Design\practice\ceshi.cpp|27|required from here|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|error: no match for ‘operator<‘ (operand types are ‘const Node‘ and ‘const Node‘)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note: candidates are:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_pair.h|220|note: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_pair.h|220|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::pair<_T1, _T2>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h|297|note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h|297|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::reverse_iterator<_Iterator>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h|347|note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h|347|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::reverse_iterator<_Iterator>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h|1055|note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h|1055|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::move_iterator<_Iterator>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h|1061|note: template<class _Iterator> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator.h|1061|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::move_iterator<_Iterator>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h|2569|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>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h|2569|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h|2581|note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h|2581|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h|2593|note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\basic_string.h|2593|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   mismatched types ‘const _CharT*‘ and ‘Node‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_vector.h|1420|note: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_vector.h|1420|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::vector<_Tp, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\array|238|note: template<class _Tp, unsigned int _Nm> bool std::operator<(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\array|238|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::array<_Tp, _Nm>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\tuple|822|note: template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const std::tuple<_Elements ...>&, const std::tuple<_Elements ...>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\tuple|822|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::tuple<_Elements ...>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_deque.h|273|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>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_deque.h|273|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_deque.h|281|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>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_deque.h|281|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_deque.h|1975|note: template<class _Tp, class _Alloc> bool std::operator<(const std::deque<_Tp, _Alloc>&, const std::deque<_Tp, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_deque.h|1975|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::deque<_Tp, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_list.h|1631|note: template<class _Tp, class _Alloc> bool std::operator<(const std::list<_Tp, _Alloc>&, const std::list<_Tp, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_list.h|1631|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::list<_Tp, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_tree.h|914|note: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_tree.h|914|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_map.h|978|note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_map.h|978|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::map<_Key, _Tp, _Compare, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_multimap.h|880|note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_multimap.h|880|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::multimap<_Key, _Tp, _Compare, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\unique_ptr.h|523|note: template<class _Tp, class _Dp, class _Up, class _Ep> bool std::operator<(const std::unique_ptr<_Tp, _Dp>&, const std::unique_ptr<_Up, _Ep>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\unique_ptr.h|523|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::unique_ptr<_Tp, _Dp>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\unique_ptr.h|534|note: template<class _Tp, class _Dp> bool std::operator<(const std::unique_ptr<_Tp, _Dp>&, std::nullptr_t)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\unique_ptr.h|534|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::unique_ptr<_Tp, _Dp>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\unique_ptr.h|540|note: template<class _Tp, class _Dp> bool std::operator<(std::nullptr_t, const std::unique_ptr<_Tp, _Dp>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\unique_ptr.h|540|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   cannot convert ‘__x‘ (type ‘const Node‘) to type ‘std::nullptr_t‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr_base.h|1090|note: template<class _Tp1, class _Tp2, __gnu_cxx::_Lock_policy _Lp> bool std::operator<(const std::__shared_ptr<_Tp1, _Lp>&, const std::__shared_ptr<_Tp2, _Lp>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr_base.h|1090|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::__shared_ptr<_Tp1, _Lp>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr_base.h|1099|note: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator<(const std::__shared_ptr<_Tp, _Lp>&, std::nullptr_t)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr_base.h|1099|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::__shared_ptr<_Tp, _Lp>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr_base.h|1104|note: template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator<(std::nullptr_t, const std::__shared_ptr<_Tp, _Lp>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr_base.h|1104|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   cannot convert ‘__x‘ (type ‘const Node‘) to type ‘std::nullptr_t‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr.h|359|note: template<class _Tp1, class _Tp2> bool std::operator<(const std::shared_ptr<_Tp1>&, const std::shared_ptr<_Tp2>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr.h|359|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::shared_ptr<_Tp1>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr.h|368|note: template<class _Tp> bool std::operator<(const std::shared_ptr<_Tp1>&, std::nullptr_t)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr.h|368|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::shared_ptr<_Tp1>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr.h|373|note: template<class _Tp> bool std::operator<(std::nullptr_t, const std::shared_ptr<_Tp1>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\shared_ptr.h|373|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   cannot convert ‘__x‘ (type ‘const Node‘) to type ‘std::nullptr_t‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_queue.h|286|note: template<class _Tp, class _Seq> bool std::operator<(const std::queue<_Tp, _Seq>&, const std::queue<_Tp, _Seq>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_queue.h|286|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::queue<_Tp, _Seq>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_set.h|769|note: template<class _Key, class _Compare, class _Alloc> bool std::operator<(const std::set<_Key, _Compare, _Alloc>&, const std::set<_Key, _Compare, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_set.h|769|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::set<_Key, _Compare, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_multiset.h|754|note: template<class _Key, class _Compare, class _Alloc> bool std::operator<(const std::multiset<_Key, _Compare, _Alloc>&, const std::multiset<_Key, _Compare, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_multiset.h|754|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::multiset<_Key, _Compare, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_stack.h|261|note: template<class _Tp, class _Seq> bool std::operator<(const std::stack<_Tp, _Seq>&, const std::stack<_Tp, _Seq>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_stack.h|261|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::stack<_Tp, _Seq>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note: template<class _Dom1, class _Dom2> std::_Expr<std::_BinClos<std::__less, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__less, typename _Dom1::value_type>::result_type> std::operator<(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const std::_Expr<_Dom2, typename _Dom2::value_type>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note: template<class _Dom> std::_Expr<std::_BinClos<std::__less, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__less, typename _Dom1::value_type>::result_type> std::operator<(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note: template<class _Dom> std::_Expr<std::_BinClos<std::__less, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__less, typename _Dom1::value_type>::result_type> std::operator<(const typename _Dom::value_type&, const std::_Expr<_Dom1, typename _Dom1::value_type>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note: template<class _Dom> std::_Expr<std::_BinClos<std::__less, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__less, typename _Dom1::value_type>::result_type> std::operator<(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const std::valarray<typename _Dom::value_type>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note: template<class _Dom> std::_Expr<std::_BinClos<std::__less, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__less, typename _Dom1::value_type>::result_type> std::operator<(const std::valarray<typename _Dom::value_type>&, const std::_Expr<_Dom1, typename _Dom1::value_type>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\valarray_after.h|416|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::valarray<typename _Dom::value_type>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\valarray|1168|note: template<class _Tp> std::_Expr<std::_BinClos<std::__less, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__less, _Tp>::result_type> std::operator<(const std::valarray<_Tp>&, const std::valarray<_Tp>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\valarray|1168|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::valarray<_Tp>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\valarray|1168|note: template<class _Tp> std::_Expr<std::_BinClos<std::__less, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__less, _Tp>::result_type> std::operator<(const std::valarray<_Tp>&, const _Tp&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\valarray|1168|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::valarray<_Tp>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\valarray|1168|note: template<class _Tp> std::_Expr<std::_BinClos<std::__less, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__less, _Tp>::result_type> std::operator<(const _Tp&, const std::valarray<_Tp>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\valarray|1168|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::valarray<_Tp>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\system_error|177|note: bool std::operator<(const std::error_code&, const std::error_code&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\system_error|177|note:   no known conversion for argument 1 from ‘const Node‘ to ‘const std::error_code&‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\system_error|250|note: bool std::operator<(const std::error_condition&, const std::error_condition&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\system_error|250|note:   no known conversion for argument 1 from ‘const Node‘ to ‘const std::error_condition&‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\forward_list.h|1359|note: template<class _Tp, class _Alloc> bool std::operator<(const std::forward_list<_Tp, _Alloc>&, const std::forward_list<_Tp, _Alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\forward_list.h|1359|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::forward_list<_Tp, _Alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|879|note: template<class _BiIter> bool std::operator<(const std::sub_match<_BiIter>&, const std::sub_match<_BiIter>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|879|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::sub_match<_BiIter>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|955|note: template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::operator<(std::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const std::sub_match<_BiIter>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|955|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘std::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1029|note: template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::operator<(const std::sub_match<_BiIter>&, std::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1029|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::sub_match<_BiIter>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1103|note: template<class _Bi_iter> bool std::operator<(const typename std::iterator_traits<_Iter>::value_type*, const std::sub_match<_BiIter>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1103|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   mismatched types ‘const typename std::iterator_traits<_Iter>::value_type*‘ and ‘Node‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1177|note: template<class _Bi_iter> bool std::operator<(const std::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1177|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::sub_match<_BiIter>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1254|note: template<class _Bi_iter> bool std::operator<(const typename std::iterator_traits<_Iter>::value_type&, const std::sub_match<_BiIter>&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1254|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::sub_match<_BiIter>‘|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1334|note: template<class _Bi_iter> bool std::operator<(const std::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\regex.h|1334|note:   template argument deduction/substitution failed:|
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h|235|note:   ‘const Node‘ is not derived from ‘const std::sub_match<_BiIter>‘|
||=== Build failed: 1 error(s), 3 warning(s) (0 minute(s), 4 second(s)) ===|

  看着似乎满屏错误,其实就是少了一个键值比较函数,因为我们知道map插入键值后默认从小到大排序,使用自定义结构体作为键值,但是没有自定义比较函数的话,编译器无法为插入的元素排序。

struct Node{
    int x,y;
    bool operator < (const Node &a)const
    {
        if (x == a.x)   return y < a.y;
        else return x < a.x;
    }
};

  这样子修改后,就可以成功运行了。其实从这个例子,我们可以类比用结构体自定义优先队列,也是需要自写比较函数的。

时间: 2024-10-03 23:04:05

std::map使用结构体自定义键值的相关文章

如何在STL的map中使用结构体作为键值

这里首先给出容器map的原型: template < class Key, class T, class Compare = less<Key>, class Alloc = alloc> class map{ ... } 可以看到模板参数一共有四个,第一个就是Key,即键:第二个就是值:第四个就是空间配置器,默认使用alloc(随STL版本不同而不同).那么第三个是啥? 我们知道,map的底层数据结构,其实是树,更确切的说,是一个RB-tree(红黑树).RB-tree树在进行插

QT: QByteArray储存二进制数据(包括结构体,自定义QT对象)

因为利用QByteArray可以很方便的利用其API对内存数据进行访问和修改, 构建数据库blob字段时必不可少; 那如何向blob内写入自定义的结构体和类 1. 利用memcpy拷贝内存数据 //自定义person结构体 Cpp代码   typedef struct { int age; char name[20]; }Person; //向QByteArray写入多个结构体 void writeStruct() { QByteArray ba; ba.resize(2*sizeof(Pers

监控服务器Zabbix之二 自定义键值及模板

一.添加主机 打开zabbix的web界面 http://192.168.212.2/zabbix 1.Configuration---Hosts---Createhost Host name:这个应该是agent 配置文件定义的Hostname,我们这是192.168.3.3. Visible name:这个就是显示名称,自定义即可. Group:将主机归类到哪个组中. 以下根据你选的监控方式来定义下面参数. Agent interfaces:就是主机上安装的agent,默认即可不用修改. S

STL: unordered_map 自定义键值使用

使用Windows下 RECT 类型做unordered_map 键值 1. Hash 函数 计算自定义类型的hash值. struct hash_RECT { size_t operator()(const RECT &rc) const { return std::_Hash_seq((const unsigned char *)&rc, sizeof(RECT)); } }; 2. 相等函数 哈希需要处理碰撞,意味着必须判断两个自定义类型对象是否相等. struct cmp_RECT

QByteArray储存二进制数据(包括结构体,自定义QT对象)

因为利用QByteArray可以很方便的利用其API对内存数据进行访问和修改, 构建数据库blob字段时必不可少; 那如何向blob内写入自定义的结构体和类 1. 利用memcpy拷贝内存数据 //自定义person结构体 Cpp代码   typedef struct { int age; char name[20]; }Person; //向QByteArray写入多个结构体 void writeStruct() { QByteArray ba; ba.resize(2*sizeof(Pers

Android(java)学习笔记105:Map集合的遍历之键值对对象找键和值

1 package cn.itcast_01; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 import java.util.Set; 6 7 /* 8 * Map集合的遍历. 9 * Map -- 夫妻对 10 * 11 * 思路: 12 * A:获取所有结婚证的集合 13 * B:遍历结婚证的集合,得到每一个结婚证 14 * C:根据结婚证获取丈夫和妻子 15 * 16 * 转换: 17 * A:获取所有键值对对象的集合 1

C/C++结构体有效对齐值的确定

看到这样一个笔试题目,如下 32位机器上定义如下结构体: struct xx { long long _x1; char _x2; int _x3; char _x4[2]; static int _x5; }; int xx::_x5; 正确答案是24. 你做对了么?下面给出解释: 结构体的有效对齐值的确定: 当未明确指定时,以结构体中最长的成员的长度为其有效值 当用#pragma pack(n)指定时,以n和结构体中最长的成员的长度中较小者为其值. 当用__attribute__ ((__p

(三十八)golang--json(对切片、map、结构体进行序列化)

JSON(javascript object notation)是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成.key-val JSON是在2001年开始推广的数据格式,目前已成为主流的数据格式. JSON易于机器解析和生成,并有效地提升网络传输效率.通常程序在网络传输时会先将数据(结构体.map)等序列化成json字符串,到接收方得到json数据时,再反序列化恢复成原来的数据类型.这种方式已成为各个语言的标准. 要解析成json格式,struct里面的字段必须大写!!!

java 遍历Map并且获取其中的键值

errCodeMap是要遍历的Map, Iterator it = errCodeMap.entrySet().iterator(); while(it.hasNext()){ Map.Entry entry = (Entry) it.next(); String key = entry.getKey().toString(); // 返回的对应map的key值 String value = entry.getValue().toString();  // 返回的对应map的value值 }