How to create a global array with a variable number of elements?

Is it possible to declare a global structure array and dynamically add elements to it?

Thank.

+3
source share
5 answers

If you want to dynamically add items to something, you can use list . You can create a global list and dynamically add items to it as needed. If you really need array type functionality, vector may be more than your speed. In this case, the STL is likely to provide you with what you need.

, . , , . .

+4

-POD . :

std::vector<YourStruct>& global_list()
{
    static std::vector<YourStruct> v;
    return v;
}

, , , , . undefined.

, . , ? ? ? .. ..

+3

. std::vector.

, , , , , STL.

+1

, . STL .

0

STL. / . .

0

Source: https://habr.com/ru/post/1752390/


All Articles