#include <iostream>
using namespace std;
class Sample
{
private:
int x;
public:
Sample () { } //1
Sample(int a){x=a;} // 2
void disp(){cout<<"x="<<x<<endl;} //3
friend Sample operator+( Sample &s1, Sample &s2);
};
Sample operator+( Sample &s1, Sample &s2) //4
{
return Sample(s1.x+s2.x);
}
int main()
{
Sample obj1(10);
Sample obj2(20);
Sample obj3;
obj3=obj1+obj2;
obj3.disp();
return 0;
}
第十二周阅读程序(1)
最新推荐文章于 2017-03-22 19:28:13 发布