cpp
#include<iostream>
using namespace std;
class Person
{
public:
string Name;
int Age;
Person(string name, int age)
{
Name = name;
Age = age;
}
bool operator==(Person& p)
{
if ((Name == p.Name) && (Age == p.Age))
{
return true;
}
else
{
return false;
}
}
bool operator>=(Person& p)
{
if ((Name >= p.Name) && (Age >= p.Age))
{
return true;
}
else
{
return false;
}
}
bool operator<=(Person& p)
{
if ((Name <= p.Name) && (Age <= p.Age))
{
return true;
}
else
{
return false;
}
}
};
int main() {
Person p1("张三", 18);
Person p2("李四", 20);
if (p1 == p2)
{
cout << "p1和p2相等" << endl;
}
else
{
cout << "p1和p2不相等" << endl;
}
}