I need to implement the overloaded the assignment operator in a class so the vector.erase
function will work properly as proposed in the answers to "vector::erase with pointer member". I have implemented also a copy constructor for the same purpose. By the following implementation of the operator I get the warning :
'Player::operator=' : recursive on all control paths, function will cause runtime stack overflow.
Apparently the implementation of Player::operator=
is incorrect. What is the correct implementation?
//Copy constructor:
Player::Player(const Player& otherPlayer) {
...
}
Player& Player::operator=(const Player& rhs) {
*this = Player(rhs);
return *this;
}
Does the erase function of a multimap work on the same way as the vector? When I use in the multimap I do not receive errors about not implementing the overloaded operator=
as it happens with vector. What is the truth?
Also, the Player has a reference to a Bank as a member. Should I do the assignment of the reference just by =? What is then the purpose of the copy constructor?