Is there a way to let the user make any number of variables or class objects without me initializing them first?
For example, I am making 2D billiard game as exercise using SFML and want the player to create the balls by clicking on the place where he wants the ball to be, I want a way for a ball to be created and named "ball_01,ball_02" every time he clicks without me making them one by one.
Other related question is how do I enter these variable in a loop or if statment?
For example, if i want to apply an if statement to check if the value of any of these variables: var1, var2, var3, var4... etc is equal to 0 without writing different if statements for each variable?
vector<ball> theBalls;
while (userIsClickingMouseButton)
{
// create ball
ball latestBall ( x_position_from_mouseclick, y_positionposition_from_mouseclick);
// put it into vector
balls.push_back(latestBall );
}
...
// loop over all balls in vector, doing something
for (int i=0; i<balls.size(); ++i)
{
// do something with balls[i]
}