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 二元运算符重载
关键词:二元运算符
内容:
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 二元运算符重载
相关文章推荐
- 1613-3-傅溥衍 总结《2016年10月5日》【连续第五天总结】
- 1613-3-傅溥衍 总结《2016年10月8日》【连续第八天总结】
- 1613-3-傅溥衍 总结《2016年10月27日》【连续第二十七天总结】
- 1613-3-傅溥衍 总结《2016年11月2日》【连续三十三天总结】
- 1613-3-傅溥衍 总结《2016年10月3日》【连续第三天总结】
- 1613-3-傅溥衍 总结《2016年11月6日》【连续三十七天总结】
- 1613-3-傅溥衍 总结《2016年10月24日》【连续第二十四天总结】
- 1613-3-傅溥衍 总结《2016年10月23日》【连续第二十三天总结】
- 1613-3-傅溥衍 总结《2016年11月4日》【连续三十五天总结】
- 1613-3-傅溥衍 总结《2016年10月9日》【连续第九天总结】
- 1613-3-傅溥衍 总结《2016年10月15日》【连续第十五天总结】
- 1613-3-傅溥衍 总结《2016年10月14日》【连续第十四天总结】
- 1613-3-傅溥衍 总结《2016年10月25日》【连续第二十五天总结】
- 1613-3-傅溥衍 总结《2016年10月21日》【连续第二十一天总结】
- 1613-3-傅溥衍 总结《2016年10月7日》【连续第七天总结】
- 1613-3-傅溥衍 总结《2016年10月12日》【连续第十二天总结】
- 1613-3-傅溥衍 总结《2016年10月17日》【连续第十七天总结】
- 1613-3-傅溥衍 总结《2016年10月29日》【连续第二十九天总结】
- 1613-3-傅溥衍 总结《2016年11月5日》【连续三十六天总结】
- 1613-3-傅溥衍 总结《2016年10月2日》【连续第二天总结】