判断结构体是否相等重载 == 号的两种方式
作者:
博爵骑士
,
2021-09-07 19:50:04
,
所有人可见
,
阅读 392
#include<bits/stdc++.h>
using namespace std;
/*
第一种(推荐,好记字又少)
struct student
{
int num, name;
}stu1, stu2;
bool operator == (student a, student b)
{
return(a.num == b.num && a.name == b.name);
}
第二种
struct student
{
int num, name;
bool operator == (const student &res);
}stu1, stu2;
bool student :: operator == (const student &res)
{
return(num == res.num && name == res.name);
}
*/
int main()
{
while(scanf("%d%d%d%d", &stu1.num, &stu1.name, &stu2.num, &stu2.name) != EOF)
{
if(stu1 == stu2) puts("Yes");
else puts("No");
}
return 0;
}
//重载过后不会影响 == 号原本的用途。