// opreator操作符的应用.cpp : 定义控制台应用程序的入口点。
//操作符operator说白了就是可以自定义一些我们可能用不到的,例如两个人的年龄比较,必须自己给其定义一个重载操作符。
#include "stdafx.h"
#include "iostream"
using namespace std;
class person{
private:
int age;
public:
person(int a)
{
this->age = a;
}
inline bool operator == (const person &ptr) const;
};
inline bool person::operator==(const person &ptr)const{
if (this->age == ptr.age)
return true;
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
person p1(100);
person p2(100);
if (p1 == p2)
{
cout << "p1 == p2 的年龄" << endl;
}
else
{
cout << "不相等" << endl;
}
//cout << "helllo world!" << endl;
return 0;
}
//操作符operator说白了就是可以自定义一些我们可能用不到的,例如两个人的年龄比较,必须自己给其定义一个重载操作符。
#include "stdafx.h"
#include "iostream"
using namespace std;
class person{
private:
int age;
public:
person(int a)
{
this->age = a;
}
inline bool operator == (const person &ptr) const;
};
inline bool person::operator==(const person &ptr)const{
if (this->age == ptr.age)
return true;
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
person p1(100);
person p2(100);
if (p1 == p2)
{
cout << "p1 == p2 的年龄" << endl;
}
else
{
cout << "不相等" << endl;
}
//cout << "helllo world!" << endl;
return 0;
}