So I know that I can set each value of an array to a "magic number" (in this case a magic string) at the time of construction like;
string * myArray[] = {"foo", "bar", "baz"};
What would be useful is if I could declare my array;
string * myArray[100];
Then later (in an if statement) set its values;
myArray = {"foo", "bar", "baz"};
(the actual array will contain ~30 magic strings, so I don't want to assign them all one at a time)
I understand that magic numbers (or magic strings) are not good. However the system I am working in is CERN's root, which is full of interesting eccentricities, and I would rather not to lose any more time searching for a neater approach. So in the interest of not letting perfect become the enemy of the good I am going to use magic numbers.
What's the quickest option here?
Edit; The accepted answer works great for c++11. If, like me, you don't have that option, here is a very-nasty-but-functional solution. (Programmers with sensibilities please shield your eyes.)
int numElements;
vector<char *> myArray;
if(someCondition){
numElements = 3;
string * tempArray[] = {"foo", "bar", "baz"}]
for(int n = 0; n < numElements; n++){
const char * element = (tempArray[n]);
myArray.push_back(element);
}
}else if(anoutherCondition){
//More stuff
}