#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
Person(string name, int age)
{
this->name = name;
this->age = age;
}
bool operator==(Person &p)
{
if (this->age = p.age && this->name == p.name)
return true;
return false;
}
string name;
int age;
};
void test()
{
Person p1("xxx", 12);
Person p2("lll", 12);
if (p1 == p2)
cout << "it is true!" << endl;
else
cout << "it is false!!" << endl;
}
int main()
{
test();
return 0;
}
C++ operator实现==重载
最新推荐文章于 2023-09-22 16:37:17 发布