下面是代码:
#include <iostream.h>
class RMB
{
public:
RMB(unsigned int d, unsigned int c);
friend RMB operator + (RMB& s1, RMB& s2);
friend RMB& operator ++ (RMB& s);
void display()
{
cout<<yuan+jf/100.0<<endl;
}
protected:
unsigned int yuan;
unsigned int jf;
};
RMB::RMB(unsigned int d, unsigned int c)
{
yuan=d;
jf=c;
while(jf>=100)
{
yuan++;
jf-=100;
}
}
RMB operator + (RMB& s1, RMB& s2)
{
unsigned int c=s1.jf+s2.jf;
unsigned int d=s1.yuan+s2.yuan ;
RMB result (d,c);
return result;
}
RMB& operator ++ (RMB& s)
{
s.jf++;
if(s.jf>=100)
{
s.jf-=100;
s.yuan++;
}
return s;
}
void main()
{
RMB d1(1, 60);
RMB d2(2, 50);
RMB d3(0,0);
d3=d1+d2;
++d3;
d3.display();
}
就是红色部分的,后面那个return的后面为什么不能用this指针。还有*this和this不何不同啊。
我一改成this就显示错误:
error C2673: '++' : global functions do not have 'this' pointer