求C++类的程序

来源:百度知道 编辑:UC知道 时间:2024/07/02 01:40:32
编译个程序:对类Point重载++(自增)、--(自减)运算符
要求+ -要用友元函数实现,+ +用成员函数实现
!!!!!!!!!!答对给分!!!!!!!!!!!!!!!!!!!!!!!!!!1

#include <iostream>
using namespace std;
class Point
{
int x;
int y;
public:
Point():x(1),y(1){}//构造函数
Point& operator++();//前++
Point operator++(int);//后++
friend Point& operator--(Point& a);//前--
friend Point operator--(Point& a, int);//后--
friend ostream& operator<<(ostream& output, Point& p);//重载输出
friend Point operator+(Point& a,Point& b);//重载+
friend Point operator-(Point& a,Point& b);//重载-

};
Point& Point::operator ++()//前++
{
++x;
++y;
return *this;
}
Point Point::operator ++(int)//后++
{
Point temp=*this;
++x;
++y;
return temp;
}
Point& operator--(Point& a)//前--
{
--(a.x);
--(a.y);
return a;
}
Point operator--(Point& a,int)//后--
{
Point temp=a;
--(a.x);
--(a.y);
return temp;
}
Point operator+(Point& a,Point& b)//+
{