#include <iostream>
#include <string>
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;
}
else
{
return false;
}
}
string m_name;
string 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();
system("pause");
return 0;
}
c++学习之路——重载运算符之比较运算符
最新推荐文章于 2024-02-07 00:34:31 发布