`
wsql
  • 浏览: 11775779 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

设计一个string类,通过重载“+=”运算符,实现对两个string类对象m1,m2的操作。

 
阅读更多

#include<iostream.h>
class string
{
private:
int x,y;
public:
string(){}
string(int a,int b)
{
x=a;y=b;
}
void display()
{
cout<<"("<<x<<","<<y<<")"<<endl;
}
void operator +=(string m2)
{
x+=m2.x;
y+=m2.y;
}
};
void main()
{

string m1(1,2),m2(3,4);
cout<<"m1:";
m1.display();
cout<<"m2:";
m2.display();
m1+=m2;
cout<<"执行m1+=m2后,m1:";m1.display();
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics