I have two classes, namely Players and Team In the Team class, I have array of Players instances, and the MAX_SİZE = 11
#define MAX 11
class Players{
// Some private and public members
};
class Team {
private:
Players players[MAX];
// Some other private and public members
};
I want to implement the addNewPlayer method in my Team class.
Whenever I call this method, I should be able to the add the name of the player to the end of this Players instances array, which is players. Now the function I consider is like :
void Team :: addNewPlayer(Players new_player){
// add new_player to the end of the array
}
I know the Stacks and Queues data structures as well. However, there is a restriction on using arrays only.
Is there any efficient way of adding new object to the array of objects in other class in general?
players[currentNumberOfPlayers] = new_player?Players players[MAX];You can't change the size of that - it's fixed atMAX.std::vectorand usestd::vector::push_back().