Sunday, 1 September 2013

why operator '=' can not match?

why operator '=' can not match?

I constantly got compilation error:
no match for 'operator=' in 'bObj1 =
Balance::operator+(Balance&)(((Balance&)(& bObj2)))'
Could you someone help to point out the reason? Thanks in advance.
code:
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 &copy)
{
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;
}

No comments:

Post a Comment