struct candim
{
char usr_id[32+1];
char vcard_no[19+1];
inline bool operator < (const candim &r) const
{
int ret = 0;
if(ret = memcmp(usr_id , r.usr_id , sizeof(usr_id ) - 1)) return (ret < 0);
return (memcmp(vcard_no , r.vcard_no , sizeof(vcard_no ) - 1) < 0);
}
//inline int add(string a, string b) {usr_id = a; vcard_no = b; return 0;}
};
重载struct candim的小于运算符,这样可以比较,比如在索引等运算中就需要重载这个运算符
如
struct candim c1,c2;
c1,c2初始化
if(c1<c2){ //不重载“<”运算符就不能比较,这里的比较是先比较usr_id,如果相同在比较vcard_no
}
重载小于号运算符,并且将这个函数作为内联函数以提高性能。