#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
Person()
{
}
Person(string name,int age)
{
m_Name = name;
m_Age = age;
}
//重载==号
bool operator==(Person &p)
{
if (this->m_Age == p.m_Age && this->m_Name == p.m_Name)
{
return true;
}
return false;
}
//重载!=号
bool operator!=(Person& p)
{
if (this->m_Age != p.m_Age && this->m_Name != p.m_Name)
{
return true;
}
return false;
}
string m_Name;
int m_Age;
};
void test01()
{
Person p1("张三",18);
Person p2("张三",11);
Person p3;
if (p1 == p2)
{
cout << "p1与p2相等" << endl;
}
else
{
cout<< "p1与p2不相等" << endl;
}
}
void test02()
{
Person p3("李四", 18);
Person p4("李四", 18);
if (p3 != p4)
{
cout << "p3不等于p4" << endl;
}
else
{
cout << "p3等于p4" << endl;
}
}
int main()
{
test01();
test02();
}