Imagine the following scenario:
class infoPlayer
{
private:
//The details are not important, just notice that the size of everything can change at any time
const std::string name;
std::shared_ptr<std::string> hand; //share ownership with player
std::vector<std::string> cantHave; //I know he does not have
std::vector<std::string> iveShown; //I have shown to him
std::vector<std::vector<std::string>> possiblyHas; //Has to have one
public:
infoPlayer(player);
~infoPlayer();
};
But then I have another class:
class player
{
private:
//Here I want an array of infoPlayer
};
I want my player
to contain the info of every other player. I have tried std::vector<infoPlayer>
, std::unique_ptr<infoPlayer>
, but it doesn't work.
The only thing I did, which worked was infoPlayer* notebook
. Imagine that then, in the player
's constructor I initialize notebook (new infoPlayer[x])
. How is memory allocated for that number of infoPlayer
s. The size of each infoPlayer
will increment throughout the game. Will this wokr?
How can I create a list of infoPlayer
s as a member of my player
?
Aucun commentaire:
Enregistrer un commentaire