Given class defined as follow:
struct A {
std::vector<int> aList;
A() {
for (int i = 0; i < ARRAY_LENGTH; i++)
aList.push_back(0);
}
}
A argument-less contructor of A is required by other part of the program. Is it possible to have ARRAY_LENGTH varies (say read from external file/modified from gui), so that
- Step 0: ARRAY_LENGTH = 10
- Step 1: create objects of A, with aList.size() initalized as 10.
- Step 2: use newly created objects of A
- Step 3: remove all previously created objects of A
- Step 4: Repeat step 0 to 4 with different values of ARRAY_LENGTH, until end of program
The modification of ARRAY_LENGTH should be either from external file, or modified by gui. and no other part of the program should have write-access to this value. How can I achieve this requirement?
Edit: For destroying existing objects, it would be handled by other part of program
Edit(2): I'm doing a simulation project, and aList in class A represents the possible pdf values of family size. (Say aList[0] = 0.5, aList[1] = 0.2, aList[3] = 0.3). The change of maximum family size will only happen when the program running different scenarios, which mean that I will destroy previously created objects of A to reset the simulation.