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 varia开发者_运维问答bles 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.
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);
}
精彩评论