关系运算符重载
约 0 个字 46 行代码 预计阅读时间 1 分钟
#include <iostream>
using namespace std;
class Person{
public:
Person(string name, int age){
this->name = name;
this->age = age;
}
bool operator==(Person & p){
if (this->name == p.name && this->age == p.age){
return true;
}
return false;
}
bool operator!=(Person & p){
if (this->name == p.name && this->age == p.age){
return false;
}
else return true;
}
string name;
int age;
};
void test1(){
Person p1("1",1);
Person p2("1",1);
cout << (p1 == p2)<<endl;
}
int main(){
test1();
return 0;
}