QMap主键是自定义类型

来源:互联网 发布:抢网络 编辑:程序博客网 时间:2024/05/22 01:58


#1 得分:40回复于: 2012-10-26 11:37:46
重载小于符号就可以了。
C/C++ code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
    }
 
};
#1 得分:40回复于: 2012-10-26 11:37:46
重载小于符号就可以了。
C/C++ code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
    }
 
};
0 0
原创粉丝点击