#include
using namespace std;
class MyInteger{
private:
int a;//50
int b;//5
public:
void set(int n){a=n;}
int get() const {return a;}
MyInteger (int m=5){b=m;}
MyInteger add(MyInteger x) { set(x.a+b); return *this;} //此时 a=55
MyInteger sub(MyInteger x) { set(x.a-b); return *this;} //a=50
MyInteger mul(MyInteger x) { set(x.a*b); return *this;}//a=250
MyInteger div(MyInteger x) { set(x.a/b); return *this;}//a=50
MyInteger mol(MyInteger x) { set(x.a%b); return *this;}//a=0
};
int main()
{
MyInteger s1;
s1.set(50);
s1.add(s1); cout << s1.get()< s1.sub(s1); cout << s1.get()< s1.mul(s1); cout << s1.get()< s1.div(s1); cout << s1.get()< s1.mol(s1); cout << s1.get()< return 0;
}
this指什么作用和用法是什么?
为什么把return *this换成get()运行结果说缺返回值?
--------------------next---------------------
阅读(1036) | 评论(0) | 转发(0) |