负号重载时的问题
我在写超大整数类HugeInt。在重载单目运算符 - (负号)时遇到点问题
HugeInt &HugeInt::operator++ (){ *this=*this+HugeInt(1);//+号已重载,且无问题 return *this;}HugeInt &HugeInt::operator-- (){ *this=*this-HugeInt(1); return *this;}HugeInt HugeInt::operator++ (int){ HugeInt ret(*this); *this=*this+HugeInt(1); return ret;}HugeInt HugeInt::operator-- (int){ HugeInt ret(*this); *this=*this-HugeInt(1); return ret;}HugeInt HugeInt::operator- () const{ HugeInt temp(*this); temp.sign=!sign; // sign 是标志HugeInt正负的bool private变量 return temp;}
HugeInt hi=1; //赋值号已重载,且无问题cout<<hi++<<endl<<hi<<endl<<-hi<<endl;
HugeInt hi=1;cout<<hi++<<endl;cout<<hi<<endl;cout<<-hi<<endl;