首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

地图主键是cstring类型的结构体, 如何重载<

2012-11-10 
map主键是cstring类型的结构体, 怎么重载structStudent{CStringnameCStringno}mapStudent, int mapSt

map主键是cstring类型的结构体, 怎么重载<
struct Student
{
  CString name;
  CString no;
}

map<Student, int> mapStudent;

该怎么重载结构体的<,求大神指教

[解决办法]
重载小于符号就可以了。

C/C++ code
struct Student{    string name;    string no;    bool operator <(const struct Student& other) const    {        if (name < other.name)              {            return true;        }        else if (name == other.name)         {            return no < other.no;        }        return false;    }}; 

热点排行