tian1.cpp

来自「c++模板小实验」· C++ 代码 · 共 49 行

CPP
49
字号
#include<iostream.h>
class point
{public:
 point& operator++();
 point operator++(int);
 point& operator--();
 point operator--(int);
 point(){_x=_y=0;}
 int x(){return _x;}
 int y(){return _y;}
private:
 int _x,_y;
};
point& point::operator++()
{_x++;
 _y++;
 return *this;
}
point point::operator++(int)
{point temp=*this;
 ++*this;
 return temp;
}
point& point::operator--()
{_x--;
 _y--;
 return *this;
}
point point::operator--(int)
{point temp=*this;
--*this;
return temp;
}
void main()
{point a;
 cout<<a.x()<<","<<a.y()<<endl;
 a++;
 cout<<a.x()<<","<<a.y()<<endl;
 ++a;
 cout<<a.x()<<","<<a.y()<<endl;
 a--;
 cout<<a.x()<<","<<a.y()<<endl;
 --a;
 cout<<a.x()<<","<<a.y()<<endl;
}

 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?