c++重写set的比较函数
结构体定义为:
struct TDataViewAgentInfo
{
// ----- 维度 -----
char m_sBankCode[10+1];
// ----- 数据 -----
char m_sAgentName[50+1];
char m_sAgentType[1+1];
char m_sState[3+1];
char m_sStateDate[19+1];
char m_sRemark[250+1];
char m_sAuditType[1+1];
long long m_lAgentStaffId;
TDataViewAgentInfo()
{
Clear();
};
inline void Clear()
{
memset(this, 0x00, sizeof(TDataViewAgentInfo));
};
};
比较函数重载的写法:
class TDataViewAgentInfoSetCmp
{
public:
bool operator ()(const TDataViewAgentInfo &x, const TDataViewAgentInfo &y) const
{
/*if ( (x.m_lAgentStaffId == y.m_lAgentStaffId)
&& (0 == strcmp(x.m_sState, y.m_sState))
&& (0 == strcmp(x.m_sAgentType, y.m_sAgentType))
)*/
int iRet = 0;
if (x.m_lAgentStaffId == y.m_lAgentStaffId)
{
string str3 = x.m_sState;
string str4 = y.m_sState;
if (str3==str4)
{
/*iRet = strcmp(x.m_sAgentType, y.m_sAgentType);
if (iRet<0)
return 1<2;
else
return 2<1;*/
string str1 = x.m_sAgentType;
string str2 = y.m_sAgentType;
return str1 < str2;
}
else if (str3<str4)
return 1<2;
else
return 2<1;
}
else
return x.m_lAgentStaffId<y.m_lAgentStaffId;
}
};
set定义为set<TDataViewAgentInfo, TDataViewAgentInfoSetCmp>
目前往set中insert数据程序就core了
比较函数要实现的是:if ( (x.m_lAgentStaffId == y.m_lAgentStaffId)
&& (0 == strcmp(x.m_sState, y.m_sState))
&& (0 == strcmp(x.m_sAgentType, y.m_sAgentType))
大神们帮忙看看怎么写比较函数,主要是字符数组的比较问题