代码:
/*
*Copyright (c) 2016, 烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp;
*作 者:岳成艳2016年5月19号;
*版 本 号:vc++6.0;
*
*问题描述:。
*程序输入:略;
*程序输出:略;
*/
#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(s.x+x);
}
int main()
{
sample obj1(20);
sample obj2(20);
sample obj3;
obj3=obj2+obj1;
obj3.disp();
return 0;
}
运行测试: