读书人

地图主键是cstring类型的结构体 如何

发布时间: 2012-11-10 10:48:51 作者: rapoo

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;    }}; 

读书人网 >C++

热点推荐