您的位置:首页 > 其它

1613-3-傅溥衍 总结《2016年12月2日》【连续第六十三天总结】

2016-12-03 00:44 190 查看
标题:友元函数与运算符重载
关键词:二元运算符
内容: 
A今日完成情况

1. 二元运算符重载60%

B具体内容

用成员函数重载二元运算符

#include<iostream>
using namespace std;
class A{
int a,b,c;
public:
A(int x=0,int y=0,int z=0)
{a=x;b=y;c=z;
}
A operator+(A t)
{
A temp;
temp.a=a+t.a;
temp.b=b+t.b;
temp.c=c+t.c;
return temp;
}
A operator+(int);
void operator+=(A t)
{
a+=t.a;
b+=t.b;
c+=t.c;
}
void print()
{
cout<<a<<'\t'<<b<<'\t'<<c<<'\n';
}
};
A A::operator+(int s)
{
A temp=*this;
temp.a+=s;
return temp;
}
int main()
{
A a1(1,2,3),a2(4,5,6),a3,a4;
a3=a1+a2;
a4=a2+100;
a1+=a3;
a3.print();
a4.print() ;
a1.print() ;
}


C明日计划

A 类型转换运算符重载

B 二元运算符重载

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐