#include<iostream>
using namespace std;
class Person
{
public:
string m_Name;
int m_Age;
Person(string name, int age) :m_Name(name), m_Age(age) {}
//chongzai
bool operator==(Person& p)
{
if (this->m_Name == p.m_Name && this->m_Age == p.m_Age) {
return true;
}
return false;
}
bool operator!=(Person& p)
{
if (this->m_Name != p.m_Name || this->m_Age != p.m_Age) {
cout << "rnm,不相等" << endl;
return true;
}
return false;
}
};
void test01(){
Person p1("Tome", 18);
Person p2("Tome", 18);
if (p1 == p2)
cout << "p1 equals 2 p2" << endl;
if (p1 != p2) {
cout << "cnm,不相等" << endl;
}
}
int main() {
test01();
}
?