/*
*copvriqht(c)2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:陈传祯
*完成日期:2016年5月19日
*版本号:v1.0
*
*问题描述
*输入描述
*程序输出
class Sample
{
private:
int x;
public:
Sample(){}
Sample(int a){x=a;}
void disp(){cout<<"x="<<x<<endl;}
friend Sample operator+(Sample &s1,Sample &s2);
};
Sample operator+(Sample &s1,Sample &s2)
{
return Sample(s1.x+s2.x);
}
int main()
{
Sample t1(50);
Sample t2(60);
Sample t3;
t3=t1+t2;
t3.disp();
return 0;
}
*copvriqht(c)2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:陈传祯
*完成日期:2016年5月19日
*版本号:v1.0
*
*问题描述
*输入描述
*程序输出
*/
#include <iostream>
using namespace std;class Sample
{
private:
int x;
public:
Sample(){}
Sample(int a){x=a;}
void disp(){cout<<"x="<<x<<endl;}
friend Sample operator+(Sample &s1,Sample &s2);
};
Sample operator+(Sample &s1,Sample &s2)
{
return Sample(s1.x+s2.x);
}
int main()
{
Sample t1(50);
Sample t2(60);
Sample t3;
t3=t1+t2;
t3.disp();
return 0;
}