/*
All rights reserced.
文件名称:main.cpp
作者:李鑫
完成日期:2016.5.31
问题描述 :阅读程序,写出程序运行结果!
*/
#include <iostream>
using namespace std;
class Sample
{
private:
int x;
public:
Sample () { }
Sample(int a){x=a;}
void disp(){cout<<"x="<<x<<endl;}
Sample operator+( Sample &s);
};
Sample Sample:: operator+( Sample &s)
{
return Sample(x+s.x);
}
int main()
{
Sample obj1(20);
Sample obj2(20);
Sample obj3;
obj3=obj1+obj2;
obj3.disp();
return 0;
}
结果: