operator +
operator ++
For example
RMB operator + (RMB& s1, RMB& s2)
{
unsigned int yuan = s1.yuan+s2.yuan;
RMB result(yuan);
return result;
}
RMB& operator ++ (RMB& s )
{
s.yuan++;
return s;
}
区别: 值返回与引用返回
运算符做成员函数的方式
RMB RMB::operator + (RMB& s)
{
int nIndex = m_nIndex + s.m_nIndex;
RMB temp(nIndex);
return temp;
}
RMB& RMB::operator ++() //前++
{
m_nIndex++ ;
return *this;
}
RMB RMB::operator ++(int) //后++
{
RMB temp(*this);
m_nIndex++;
return temp;
}
RMB& RMB::operator = (RMB& s)
{
m_nIndex = s.m_nIndex;
return *this;
}