Hello. I am still new to object-oriented programming in C++ and I'm having difficulty in dealing with classes. We are tasked to create a multiplayer game in school which has a Player and Team class with some attributes listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13
class Player {
public:
Player();
string name;
string typeOfPlayer;
int teamNumber;
}
class Team {
public:
Team();
int numberOfPlayers;
}
The user is supposed to enter the number of players, the type of player and their team number. So I created a vector of Player instances, which I call a team.
vector<Player> team[numberOfTeams];
Then everytime a user inputs a player, it is placed inside the vector like so:
team[teamNumber].push_back(Player);
Now my problem is, how am I supposed to pass this team vector to a Team class? I have tried making an instance of Team class like:
Team team[teamNumber];
But I cannot access the array elements of team vector inside Team class when I do this. Basically I need to store instances of Player class inside Team class. Any help or guidance would be appreciated. Thank you!