lundi 4 mars 2019

Creating and populating a vector within a loop

I have a class Player which have id,color and name.

I also have a vector of Players.

I would like to create 50 Players. 10 Players per color. Meaning 10 playrs in red, 10 in black etc..

I can do somethihng like :

Player player1(1, "black", "player1");

And then add it to the vector :

players.addPlayer(&player1);

But I don't think that manually creating and inserting them is the best way to do this.

I would like to create a loop in which I will create the player and add him to the vector.I just don't know how to give a different color to every 10th player..

Aucun commentaire:

Enregistrer un commentaire