我经常遇到编译错误:
'bObj1 = Balance::operator+(Balance&)(((Balance&)(& bObj2)))'中的 'operator=' 不匹配</p>
有人能帮忙指出原因吗?提前致谢。
代码:
class Balance
{
public:
Balance (int b = 0) {balance = b;};
Balance (Balance &);
Balance & operator= (Balance &);
Balance operator+ (Balance &);
int get() {return balance;};
void set(int b) {balance = b;};
private:
int balance;
};
Balance & Balance::operator=(Balance ©)
{
balance = copy.get();
return *this;
}
Balance Balance::operator+ (Balance &rig)
{
Balance add;
add.set(this->get() + rig.get());
return add;
}
int main()
{
Balance bObj1, bObj2(100);
bObj1 = bObj2;
bObj1 = bObj1 + bObj2; // This line cause the error.
return 0;
}