今天DEBUG又发现一个BUG:
简写如下:
Code
其中bool operator<(const ID& rid)const重载操作符中的大小判断决定了MAP中的KEY采用结构中的哪个变量.
事列代码中的结构是第二个结构放入MAP中后,会覆盖第一个数据.(MAP中SIZE==1)
PS:
MAP采用数组方式插入VALUE,倘若先前有这个KEY的话是会直接覆盖的.
1#pragma warning(disable:4786)
2#include <map>
3using namespace std;
4struct ID
5{
6 int ChannelID;
7 int SubSessionID;
8 bool operator<(const ID& rid)const
9 {//for map.find & map.insert
10 return (ChannelID < rid.SubSessionID);
11 }
12};
13
14int main(int argc, char* argv[])
15{
16 map<ID,int> id_map;
17 ID id1;
18 ID id2;
19 id1.ChannelID = 1;
20 id1.SubSessionID = 2;
21
22 id2.ChannelID = 1;
23 id2.SubSessionID = 4;
24
25 id_map[id1] = 5;
26 id_map[id2] = 6;
27
28 return 0;
29}