开发者

creating a changing amount of pointers in c++

开发者 https://www.devze.com 2023-01-13 06:55 出处:网络
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开发者

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

精彩评论

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

关注公众号