#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
// 重载关系运算符
class Person
{
public:
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;
}
string m_Name;
int m_Age;
};
void test01()
{
Person p1("tom", 18);
Person p2("tom", 18);
if (p1 == p2)
{
cout << " p1 == p2" << endl;
}
else {
cout << " p1 != p2" << endl;
}
}
int main() {
test01();
}
c++ 学习 之 关系运算符重载
最新推荐文章于 2024-07-21 22:06:29 发布