I have a variable called vector_size. The value of this variable is inputted by the user at run time. I also have a class MyClass.
I want to create a vector of MyClass. I want the vector to have vector_size elements. How would I do this?
This is what I've tried so far:
vector <MyClass> myVector (vector_size) = MyClass(); The code above doesn't work. How would I make a vector of vector_size, and each element is initialized?
Note that I do not want to just "reserve space" for vector_size elements. I want the vector to be populated with vector_size elements, and each element needs to be initialized with the constructor.
Essentially, I want to do the following in one line:
vector <MyClass> myVector; for (int counter = 0; counter < vector_size; counter++) { myVector.pushBack (MyClass()); }