#include <iostream>
class twelfth_class_1{
int i;
public:
twelfth_class_1(int ii=0 ){
i = ii;
}
const twelfth_class_1 operator+(const twelfth_class_1 &tc1)const {
twelfth_class_1 x(this->i+tc1.i);
return x;
}
const twelfth_class_1 operator-(const twelfth_class_1 &tc1)const{
twelfth_class_1 x(this->i-tc1.i);
return x;
}
friend std::ostream& operator<<(std::ostream&os,twelfth_class_1& tc1);
};
inline std::ostream& operator<<(std::ostream&os,twelfth_class_1& tc1){
return os<<"twelfth_class_1对象的值为"<<tc1.i;
class twelfth_class_1{
int i;
public:
twelfth_class_1(int ii=0 ){
i = ii;
}
const twelfth_class_1 operator+(const twelfth_class_1 &tc1)const {
twelfth_class_1 x(this->i+tc1.i);
return x;
}
const twelfth_class_1 operator-(const twelfth_class_1 &tc1)const{
twelfth_class_1 x(this->i-tc1.i);
return x;
}
friend std::ostream& operator<<(std::ostream&os,twelfth_class_1& tc1);
};
inline std::ostream& operator<<(std::ostream&os,twelfth_class_1& tc1){
return os<<"twelfth_class_1对象的值为"<<tc1.i;
}
int main{
twelfth_class_1 tc1(521);
cout<<tc1<<endl;
twelfth_class_1 tc2(123);
twelfth_class_1 tc3 = tc1+tc2;
cout<<tc3<<endl;
twelfth_class_1 tc4 = tc1-tc2;
cout<<tc4<<endl;
twelfth_class_1 tc5 = tc1+tc2-tc4;//tc1+tc2产生一个临时变量,const只能调用const函数
//所以这里的+与-必须为const 不然编译器会报错。
}