函数重载:参数个数、类型,顺序不同,不能仅通过函数返回值重载
运算符重载:
#include <iostream>
using namespace std;
class Point{
public:
//成员数据
int x;
int y;
Point operator +(Point ptmp);
};
Point Point:: operator +(Point ptmp)
{
Point p;
p.x = x + ptmp.x;
p.y = y + ptmp.y;
return p;
}
int main()
{
cout << "Hello World!" << endl;
Point p1;
p1.x = 3;
p1.y = 4;
Point p2;
p2.x = 5;
p2.y = 6;
Point p3 = p1 + p2; //两个对象相加("+")的运算符
cout << "p3.x=" <<p3.x<< " p3.y=" <<p3.y<<endl;
return 0;
}