I have a project im working on where I need to make an array that stores pointers but the number and size of the array will change at run time each time it runs. is there any way to declare variables in a for loop or something like that where i can declare a variable in the format of pointername with a number at the end.
+5
A:
A std::vector
, a core part of the C++ library, suits your needs perfectly -- have an #include <vector>
at the top of your source, then, when needed, e.g:
...
std::vector<Foo*> foo_pointers;
while(Foo* onemore_pointer = some_weird_func()) {
foo_pointers.push_back(onemore_pointer);
}
Alex Martelli
2010-08-29 03:57:11