关于unordered_set
  • 板块灌水区
  • 楼主Grace25
  • 当前回复6
  • 已保存回复6
  • 发布时间2020/10/16 20:44
  • 上次更新2023/11/5 10:38:06
查看原帖
关于unordered_set
359883
Grace25楼主2020/10/16 20:44

为了备考,看了管理员阮行止的旧课

其中有一课,说unordered_set不能用结构体

可经测试,可以用结构体呀

测试代码如下↓

#include<iostream>
#include<cstring>
#include<unordered_set>
using namespace std;
int sum;
struct student{
    char name[70];
    int level;
    int id=++sum;
    bool operator==(const student& a) const{
        return !(strcmp(a.name,name)) && level == a.level;
    }
};
struct test_hash{
    int hash(student o){
        return o.id;
    }
};
int main(){
    unordered_set<student,test_hash> our_class;
    return 0;
}
2020/10/16 20:44
加载中...