在使用容器盛放自定义结构体时,有些容器会进行默认排序,例如map就是以默认的由小到大的顺序存放数据,这就需要在自定义结构体时重载‘>’、‘<’、‘=’等运算符,例如
typedef struct AddrName{
CString sPinyin;
CString sHanzi;
int i;
bool operator < (const AddrName &temp) const
{
if (this->i < temp.i) return true;
if (this->i == temp.i) return this->sPinyin.Compare(temp.sPinyin) < 0;
return false;
}
}_AddrName;