operator

来源:互联网 发布:淘宝客服主管绩效考核 编辑:程序博客网 时间:2024/06/04 18:25
#include <iostream>#include <windows.h>#include <tchar.h>using namespace std;class Test{public:Test(){};Test(int a,int b){x=a,y=b;}Test operator+(Test t){Test temp;temp.x=x+t.x;temp.y=y+t.y;return temp;}void operator-(Test t){this->x=this->x-t.x;this->y=this->y-t.y;return;}int x;int y;};int main(void){Test t1(1,2);Test t2(2,3);Test t3;t3=t1+t2;cout<<t3.x<<endl<<t3.y<<endl;cout<<"---------------------------"<<endl;t2-t1;cout<<t2.x<<endl<<t2.y<<endl;return 0;}/*2015年3月3日9:59:57程序执行结果如下:35---------------------------11请按任意键继续. . .*/

0 0
原创粉丝点击