#include<iostream>
using namespace std;
class point1
{
int x;int y;
public:
point1(int ix=0,int iy=0)
{
x=ix;
y=iy;
}
int getx()
{
return x;
}
int gety()
{
return y;
}
point1 operator++();
point1 operator--();
point1 operator++(int);
point1 operator--(int);
};
point1 point1::operator++()
{
this->x++;
this->y++;
return *this;
}
point1 point1::operator--()
{
this->x--;
this->y--;
return *this;
}
point1 point1::operator++(int)
{
point1 temp;
temp.x=this->x;
temp.y=this->y;
this->x++;
this->y++;
return temp;
}
point1 point1::operator--(int)
{
point1 temp;
temp.x=this->x;
temp.y=this->y;
this->x--;
this->y--;
return temp;
}
int main()
{
point1 a(6,14);
a--;
cout<<a.getx()<<","<<a.gety()<<endl;
a++;
cout<<a.getx()<<","<<a.gety()<<endl;
--a;
cout<<a.getx()<<","<<a.gety()<<endl;
++a;
cout<<a.getx()<<","<<a.gety()<<endl;
point1 b;
b=a--;
cout<<b.getx()<<","<<b.gety()<<endl;
b=a++;
cout<<b.getx()<<","<<b.gety()<<endl;
b=--a;
cout<<b.getx()<<","<<b.gety()<<endl;
b=++a;
cout<<b.getx()<<","<<b.gety()<<endl;
return 0;
}
8-7对point重载++,--
最新推荐文章于 2022-06-14 19:28:43 发布