关系运算符重载

关系运算符重载

 

#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
	int m_age;
	string m_name;

	Person(int age,string name)
	{
		m_age = age;
		m_name = name;
	}

	//重载运算符==
	bool operator==(Person &p)
	{
		if (m_age == p.m_age && m_name == p.m_name)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
};


int main() 
{
	Person p1(18,"Bruce");
	Person p2(18, "Bruce");
	if (p1 == p2)
	{
		cout << "p1和p2相等" << endl;
	}
	else
	{
		cout << "p1和p2不相等" << endl;
	}

	system("pause"); 
	return 0;
}

 

上一篇:格式化HDFS出现java.io.IOException: Cannot create directory /opt/hdfs/name/current错误


下一篇:Python 为什么要保留显式的 self ?