/*
*Copyright (c) 2016 烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:test.cpp
*作 者:史红浩
*完成日期:2016年 6 月 5 日
*版 本 号: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 &sl,Sample &s2);
};
Sample operator+(Sample &s1,Sample &s2)
{
return Sample(s1.x+s2.x);
}
int main()
{
int a1,a2;
cin>>a1>>a2;
Sample obj1(a1);
Sample obj2(a2);
Sample obj3;
obj3=obj1+obj2;
obj3.disp();
return 0;
}
运行结果: