C++.阅读程序,写出运行结果,求大神。 15
#include"iostream.h"classSample{private:intx;public:Sample(){}Sample(inta){x=a;}voidd...
#include "iostream.h"
class Sample{
private: int x;
public : Sample( ){ }
Sample(int a ){x=a;
}
void
disp(){cout<<"x="<<x<<endl;}
Sample
operator+(Sample &);
friend Sample operator-(Sample &,Sample &);
};
Sample Sample ::operator+(Sample
&s){return Sample(x+s.x); }
Sample operator-(Sample &s1,Sample
&s2){return Sample(s1.x-s2.x); }
void main(){ Sample obj1(5),obj2(10),obj3;
obj3=obj1+obj2;
obj3.disp(); (obj1-obj2).disp();
} 展开
class Sample{
private: int x;
public : Sample( ){ }
Sample(int a ){x=a;
}
void
disp(){cout<<"x="<<x<<endl;}
Sample
operator+(Sample &);
friend Sample operator-(Sample &,Sample &);
};
Sample Sample ::operator+(Sample
&s){return Sample(x+s.x); }
Sample operator-(Sample &s1,Sample
&s2){return Sample(s1.x-s2.x); }
void main(){ Sample obj1(5),obj2(10),obj3;
obj3=obj1+obj2;
obj3.disp(); (obj1-obj2).disp();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询