I'm looking for a way to create class objects through a for loop. For reference, I'm trying to create a class of objects, user input will determine how many objects are needed. I'm using a constructor within a for loop to do this, but it requires the object name to be variable. I've tried a lot of methods, nothing has worked, including vectors. I literally started using C++ a day ago, so ignore the messy code or foolish errors unless they are pertinent to the question, its a pet project.
// Enemy Names
string eNames[ENum]{};
// Enemy Initiatives
double eInits[ENum]{};
//Enemy Temp ID's
int eTempids[ENum]{};
// Enemy Names Vector
std::vector<EnemyClass> en(ENum);
if (ENum > 0) {
for(int i = 0; i < ENum; i++){
string name;
double init;
int tempid = i + PLAYER;
cout << "Enter Enemy " << i + 1 << "'s Name" << endl;
cin >> name;
cout << "Enter " << name << "'s Initiative" << endl;
cin >> init;
eNames[i] = name;
eInits[i] = init;
eTempids[i] = tempid;
EnemyClass en[i](string name, double init, int tempid);
};
}; // END of IF Statement
en[i] is what needs to be the variable name. I either get an error stating that "deceleration of 'en' as array of functions" or that 'EnemyClass' is not a declared function, Not sure how to use that it was an attempt from another forum post I found:
Question was the same as mine with below code:
for (int count = 0; count < no_of_objects; count ++)
{
ClassName object_name[count]
}
Answer code:
std::vector<ClassName> objects (no_of_objects);
But this produces the "Not a declared function" error in the stl_construct.h file