【发布时间】:2014-09-27 11:51:30
【问题描述】:
我知道这意味着什么,但在我的情况下,我不明白为什么我的 IDE 会为此大喊大叫。
Rational operator*(const Rational& that1, const Rational& that2)
{
Rational temp(that1);
temp.getNom() *= that2.getNom();
temp.getDenom() *= that2.getDenom();
return temp;
}
int Rational::getNom() const
{
return m_iNom / gcd(m_iNom, m_iDenom);
}
int Rational::getDenom() const
{
return m_iDenom / gcd(m_iNom, m_iDenom);
}
float Rational::gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
m_iNom 和 m_iDenom 是 Rational 类中的私有数据成员。
我得到'表达式必须是可修改的左值':
temp.getNom() *= that2.getNom();
temp.getDenom() *= that2.getDenom();
【问题讨论】: