作用:重载关系运算符,可以让两个自定义类型对象进行对比操作
#include"cf_17.h"
class PersonP
{
public:
PersonP(string name ,int age)
{
this->name = name;
this->age = age;
}
// 重载关系运算符
bool operator ==(const PersonP& p)
{
if (p.name == this->name && p.age == this->age)
{
return true;
}
else
{
return false;
}
}
string name;
int age;
};
void cf_17_test_01()
{
PersonP p1("Max", 10);
PersonP p2("Max", 11);
cout << (p1 == p2) << endl;
}