STL中map的结构体查找?
#pragma warning(disable:4786)
#include <iostream>
#include <map>
#include <functional>
using namespace std;
typedef struct ITEM
{
int i;
int j;
} Item;
template <class T>
struct A_less : public binary_function <T, T, bool >
{
bool operator()(T lhs, T rhs)
{
return lhs.i < rhs.i;
}
};
typedef map <Item,int,A_less <Item> > IntMap;
typedef map <Item,int,A_less <Item> > ::value_type MVT;
typedef map <Item,int,A_less <Item> > ::iterator MapItor;
void main()
{
IntMap map1;
Item ItemTemp;
ItemTemp.i = 10;
ItemTemp.j = 11;
map1.insert(MVT(ItemTemp,2));
map1.find(ItemTemp);//该如何改?
}
[解决办法]
不过最好还是改成:
bool operator()(const T& lhs, const T& rhs) const