MAP--复杂map结构的构造
来源:互联网 发布:剑灵数据库下载 编辑:程序博客网 时间:2024/06/05 09:23
我的关键结构比如
struct{
int a;
int b;
int c;
}s;
因为这三个数据是基本信息,可以唯一区别一个设备。拿这样一个数据结构作为索引就能找到每个设备。
我现在想这么用
map<s, string>
因为map是二叉树,好像没法拿结构体比较大小,去索引,所以把结构体s改成类,重载小于号,让他能比较大小。
class s
{
public:
int a;
int b;
int c;
s(int m, int d, int u){a=m;b=d;c=u;}
bool operator < (const s &other)
{
if ((a<other.a) ||
((a==other.a)&&(b<other.b)) ||
((a==other.a)&&(b==other.b)&&(c<other.c)))
{
return true;
}
return false;
}
};
然后,
map<s, string> w;
s s1;
string s2;
一旦执行w.insert(make_pair(s1, s2));只要有这行就立刻报错。
要想使用一个类似结构体的数据结构作为KEY到底要怎么做呀?
是不是光重载一个小于号不够呀?
我现在好糊涂。有没有简单办法?
1.1
struct s {
int a;
int b;
int c;
bool operator<(const s&) const { return true; }
};
map<s,string> m;
m.insert( make_pair(s(),"") );
1.2
struct s {
int a;
int b;
int c;
};
bool operator<(const s&,const s&) { return true; }
map<s,string> m;
m.insert( make_pair(s(),"") );
2.
struct s {
int a;
int b;
int c;
};
struct cmp {
bool operator()(const s&,const s&) const { return true; }
};
map<s,string,cmp> m;
m.insert(make_pair(s(),"" ) );
转载自:http://bbs.chinaunix.net/thread-1538318-1-1.html
- MAP--复杂map结构的构造
- JS构造Map结构
- map的弱化构造
- jquery前端递归打印出树状结构的多层复杂map或json键值对数据
- json字符串转为map结构,复杂json字符串转为map结构
- 遍历一个复杂的Map对象。
- go语言map的复杂用法
- FreeMarker 解析复杂 Map
- 复杂Map遍历
- vector,list和map的构造
- js中MAP集合的构造
- Cxf 复杂数据类型(Map)
- Jersey 复杂类型返回 Map
- Cxf 复杂数据类型(Map)
- 复杂json转MAP对象
- js构造MAP
- JavaScript Map构造函数
- 使用Struts2的iterator标签遍历复杂的Map类型
- 2013C++第9周项目——多分支结构程序设计
- 网页中播放视频文件
- Redis安装 For CentOS6.4_64
- gvim常用操作
- .net httpHandler和httpModule
- MAP--复杂map结构的构造
- 键盘过滤驱动 NT(解决unload后再按键蓝屏问题)
- WCF-003:关于 WCF 基础连接已经关闭 连接被意外关闭-序列化问题
- Js控制flash的操作(非常有用)
- 关于android SDK安装Failed to fetch URL http://dl-ssl.google.com/android/repository/addons_list-1.xml出错
- 利用java程序模拟登陆新浪微博
- JQ多文件文件上传插件
- <Unity3D>Unity3D中MeshRenderer的使用
- zygote