I'm having a hard time understanding how to implement operator overloading. I have a simple Account class with the variables name (char[]) and balance (double). I need to overload the += operator and = operator to do the following:
Overload the operator+= so that: If A and B and C are Account objects: A = B += C: adds the balance of C to B and returns the reference of B, so A will be to B afterwards.
Overload the operator= so that: A = B = "new name": Sets the name of B to “new name” and returns the reference of B.
I don't know if its the wording or what but I just don't understand what I should be doing here.
I've made these declarations in my header file although I'm not sure if this correct:
//Overload the operator+=
Account& operator+=(const Account&);
//Overload the operator=
Account& operator=(const Account&);
I don't even know where to start with the cpp file because I'm not even sure if my declaration is correct. This is what I've done although I'm pretty sure it's wrong (especially the 2nd one).
Account& Account::operator+=(const Account& account) {
this->balance_ += account.balance_;
return *this;
}
Account& Account::operator=(const Account& account) {
strncpy(this->name_, "new name", MAX_NAME);
return *this;
}