#include
using namespace std;
/*
定义Point类
有坐标x,y两个成员变量,
对Point类重载 “++” (自增),”--”(自减)运算符,实现对坐标值的改变
包含前置与后置
*/
class Point{
public:
Point(){ }
Point(int x,int y);
~Point(){ }
Point& operator++();//对应于++a
Point operator++(int);//对应于a++
Point& operator--();//对应于--a
Point operator--(int);//对应于a--
friend ostream& operator<<(ostream& out, const Point& a);//友元函数cout< friend void operator>>(istream&in, Point& a);//友元函数cin>>a
public:
int x;
int y;
};
Point::Point(int x,int y){
this->x=x;
this->y=y;
}
Point& Point::operator++(){//++a
this->x++;
this->y++;
return *this;
}
Point Point::operator++(int){//a++
Point tmp(this->x,this->y);
this->x++;
this->y++;
return tmp;
}
Point& Point::operator--(){//--a
this->x--;
this->y--;
return *this;
}
Point Point::operator--(int){//a--
Point tmp(this->x,this->y);
this->x--;
this->y--;
return tmp;
}
ostream& operator<<(ostream& out, const Point& a){//友元函数cout< out<<"点为:("<
}
void operator>>(istream&in, Point& a){//友元函数cin>>a
int px,py;
cout<<"输入x:"; cin>>px;
cout<<"输入y:"; cin>>py;
a.x=px;
a.y=py;
}
void main()
{
cout<<"第一次运行速度有点慢^_^"<
cin>>a;
cout<
//cout<<"a++:"< cout<<"++a:"<<++a;
//cout<<"a--:"<
}
++/-- 怎么改变坐标值? x 和 y同时改变?