开发者

creating a changing amount of pointers in c++

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜