Insert std::map::插入故障

Insert std::map::插入故障,insert,stdmap,Insert,Stdmap,我有一个非常简单和愚蠢的问题: std::map<b2Vec2, b2Body*> mTakePoints; mTakePoints.insert(std::make_pair(point, body)); std::映射mTakePoints; mTakePoints.insert(std::make_pair(point,body)); 编译器说: In file included from /usr/include/c++/4.4/string:50,

我有一个非常简单和愚蠢的问题:

std::map<b2Vec2, b2Body*> mTakePoints;
mTakePoints.insert(std::make_pair(point, body));
std::映射mTakePoints;
mTakePoints.insert(std::make_pair(point,body));
编译器说:

In file included from /usr/include/c++/4.4/string:50,
                 from /usr/include/ClanLib-2.2/ClanLib/Display/../Core/Text/string_types.h:34,
                 from /usr/include/ClanLib-2.2/ClanLib/Display/display.h:35,
                 from /usr/include/ClanLib-2.2/ClanLib/display.h:40,
                 from /home/pfight/Themisto/include/World/Actions/Action.hpp:21,
                 from /home/pfight/Themisto/include/World/Actions/TakeAction.hpp:21,
                 from /home/pfight/Themisto/src/World/Actions/TakeAction.cpp:18:
/usr/include/c++/4.4/bits/stl_function.h: In member function ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = b2Vec2]’:
/usr/include/c++/4.4/bits/stl_tree.h:1170:   instantiated from ‘std::pair<typename std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(const _Val&) [with _Key = b2Vec2, _Val = std::pair<const b2Vec2, b2Body*>, _KeyOfValue = std::_Select1st<std::pair<const b2Vec2, b2Body*> >, _Compare = std::less<b2Vec2>, _Alloc = std::allocator<std::pair<const b2Vec2, b2Body*> >]’
/usr/include/c++/4.4/bits/stl_map.h:500:   instantiated from ‘std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const std::pair<const _Key, _Tp>&) [with _Key = b2Vec2, _Tp = b2Body*, _Compare = std::less<b2Vec2>, _Alloc = std::allocator<std::pair<const b2Vec2, b2Body*> >]’
/home/pfight/Themisto/src/World/Actions/TakeAction.cpp:43:   instantiated from here
/usr/include/c++/4.4/bits/stl_function.h:230: error: no match for ‘operator<’ in ‘__x < __y’
/usr/include/ClanLib-2.2/ClanLib/Display/../Core/Text/string_data16.h:383: note: candidates are: bool operator<(const CL_StringData16&, const wchar_t*)
/usr/include/ClanLib-2.2/ClanLib/Display/../Core/Text/string_data16.h:382: note:                 bool operator<(const wchar_t*, const CL_StringData16&)
/usr/include/ClanLib-2.2/ClanLib/Display/../Core/Text/string_data16.h:381: note:                 bool operator<(const CL_StringData16&, const CL_StringData16&)
/usr/include/ClanLib-2.2/ClanLib/Display/../Core/Text/string_data8.h:383: note:                 bool operator<(const CL_StringData8&, const char*)
/usr/include/ClanLib-2.2/ClanLib/Display/../Core/Text/string_data8.h:382: note:                 bool operator<(const char*, const CL_StringData8&)
/usr/include/ClanLib-2.2/ClanLib/Display/../Core/Text/string_data8.h:381: note:                 bool operator<(const CL_StringData8&, const CL_StringData8&)
在/usr/include/c++/4.4/string:50中包含的文件中,
来自/usr/include/ClanLib-2.2/ClanLib/Display/。/Core/Text/string_types.h:34,
从/usr/include/ClanLib-2.2/ClanLib/Display/Display.h:35,
从/usr/include/ClanLib-2.2/ClanLib/display.h:40,
from/home/pfight/Themisto/include/World/Actions/Action.hpp:21,
from/home/pfight/Themisto/include/World/Actions/TakeAction.hpp:21,
from/home/pfight/Themisto/src/World/Actions/TakeAction.cpp:18:
/usr/include/c++/4.4/bits/stl_function.h:在成员函数“bool std::less::operator()(const _Tp&,const _Tp&)const[with _Tp=b2Vec2]”中:
/usr/include/c++/4.4/bits/stl_tree.h:1170:从“std::pair std::_Rb_tree:::_M_insert_unique(const _Val&)[带_Key=b2Vec2,_Val=std::pair,_KeyOfValue=std:_Select1st,_Compare=std::less,_Alloc=std::分配器]'
/usr/include/c++/4.4/bits/stl_-map.h:500:从“std::pair std::map::insert(const std::pair&)[with _Key=b2Vec2,_Tp=b2Body*,_Compare=std::less,_Alloc=std::allocator]”实例化
/home/pfight/Themisto/src/World/Actions/TakeAction.cpp:43:从此处实例化

/usr/include/c++/4.4/bits/stl_function.h:230:错误:与“operator”不匹配是否定义了以下运算符:

bool operator< (const b2Vec2&, const b2Vec2&)
bool运算符<(常数b2Vec2&,常数b2Vec2&)

std::map
要求为键定义小于运算符,或者提供小于运算符作为模板参数。特别是,
std::map
实现为一个(排序的)二叉树,需要运算符<来确定新项目的放置位置。

您是否定义了以下运算符:

bool operator< (const b2Vec2&, const b2Vec2&)
bool运算符<(常数b2Vec2&,常数b2Vec2&)

std::map
要求为键定义小于运算符,或者提供小于运算符作为模板参数。特别是,
std::map
实现为一个(排序的)二叉树,需要运算符<来确定新项目的放置位置。

对于map、set和类似的已排序容器,必须告知新项目的放置位置。这是通过实现小于运算符来实现的:

bool operator< (const b2Vec2& first, const b2Vec2& second) 
{
   return first.some_attribute < second.some_attribute;
}
bool运算符<(常数b2Vec2和第一个,常数b2Vec2和第二个)
{
返回first.some\u属性
您可以在编译错误中看到它丢失了:

/usr/include/c++/4.4/bits/stl_function.h:230: error: no match for ‘operator<’ in ‘__x < __y’

/usr/include/c++/4.4/bits/stl_function.h:230:错误:map、set等订购容器的“operator”不匹配必须告知新项目的放置位置。这是通过实现小于运算符来实现的:

bool operator< (const b2Vec2& first, const b2Vec2& second) 
{
   return first.some_attribute < second.some_attribute;
}
bool运算符<(常数b2Vec2和第一个,常数b2Vec2和第二个)
{
返回first.some\u属性
您可以在编译错误中看到它丢失了:

/usr/include/c++/4.4/bits/stl_function.h:230: error: no match for ‘operator<’ in ‘__x < __y’
/usr/include/c++/4.4/bits/stl_function.h:230:错误:与“运算符”不匹配