【发布时间】:2018-03-11 19:21:03
【问题描述】:
这是我的函数原型:
Rational & operator+=(const Rational &);
这是我班级的一部分:
class Rational
{
public:
Rational(int a = 0, int b = 1) : n(a), d(b) {}
这是我的功能:
Rational & Rational::operator+=(const Rational & r)
{
return (r + *this);
}
我已经做了一个函数来添加两个有理数。 当我尝试编译它时,我收到以下错误:
error: cannot bind non-const lvalue reference of type
‘Rational&’ to an rvalue of type ‘Rational’
return (r + *this);
我做错了什么?
【问题讨论】:
-
您似乎不知道简单的技巧:首先在谷歌上搜索错误消息通常是个好主意...