首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

STL中map的结构体查找?该怎么解决

2012-03-11 
STL中map的结构体查找?#pragmawarning(disable:4786)#includeiostream#includemap#includefunctional

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

热点排行