Based on issues growing out of previous questions: vector::erase with pointer member, Remove elements of a vector inside the loop, I still need some help on vector.erase function. I was indicated to implement a copy constructor to make the erase function work on a vector, something that is also mentioned in another question. It is essential to implement a function operator in my relevant class. On doing this I get another error on creating the copy constructor and I cannot find the reason for long. The error is “Player::Player(const Player& otherPlayer) does not provide an initiallizer for:” . What am I doing wrong? Take into consideration that Player contains as class members map, pointers and a reference (bank is a reference) . Is a simple assignment adequate for the initialization?
What should I do?
class Player
{
public:
Player(int,int,string, Bank&);
Player(const Player&);
Player& operator = (const Player& rhs);
Player::Player(const Player& otherPlayer)
{
ID = otherPlayer.ID;
pName = otherPlayer.pName;
pMoney = otherPlayer.pMoney;
doubleIndicator = otherPlayer.doubleIndicator;
position = otherPlayer.position;
bank = otherPlayer.bank;
colBought = otherPlayer.colBought;
housesColBuilt = otherPlayer.housesColBuilt;
}
Update: I get a warning at the point of implementantion of the operator= as:"returning address of a local variable or temporary". Does this evoke a real problem? If so, how could I modify it to get over this?
Player& Player::operator=(const Player& rhs)
{
return Player(rhs);
}
In this way, I still receive a warning that the recursive function will cause stack overflow:
Player& Player::operator=(const Player& rhs)
{
*this = Player(rhs);
return *this;
}
Any hint?