I’m trying to do something simple and store an object into an Array in C++ but it keeps saying that I can’t use the = operator with the right hand operand being of my class. Here’s the code:
class Player {
string name;
double points;
bool wonLastRound;
public:
Player() {}
Player(string n)
{
name = n;
}
const Player &operator=(const Player &);
void addPoints(double p)
{
points += p;
}
};
and here’s the code to instantiate
void initPlayers()
{
for(int i = 0; i < 4; i++)
players[i] = new Player("Player " + i);
}
any help would be appreciated, I really need to get this project finished soon!
It should be,
Actual problem lies in assignment inside
forloop. You don’t have tonewthe objects, as you are storing value and not the pointer.Usage: