Passing an argument into the constructor of an array of objects

class Player{
public:
Player(int NumberOfStats){
NumOfStats=NumberOfStats;
}
private:
int NumOfStats;

};

int main (){
int x,y;
string s;
cout << "Player: ";
cin >> x;
Player n[x]; //need to pass arguments for each object constructor

for(int i=0; i<y; i++){
cin >> s;
}
for (int i=0; i<y; i++){
}


}
Can't be done. You need to use a vector or an array of pointers.
how can you do that
For example,
1
2
3
4
5
std::vector<Player> players;
players.emplace_back(5); //Calls Player::Player(4)
players.emplace_back(3); //etc.
players.emplace_back(9);
players.emplace_back(4);
Topic archived. No new replies allowed.