0

New to C++. Working with: GCC C++ Compiler; Eclipse Neon (4.6.0); OS X Sierra

I have a program with an object type ArrangementNode, one member of which is an array of ints called occupiedArray. I do not know how many ints occupyArray needs to hold until runtime, so I want the size of occupiedArray to be an int variable with a value determined at runtime. But, the compiler will not let me initialize the array with a variable size: error: fields must have a constant size: 'variable length array in structure' extension will never be supported.

This has to be a common need in C++. How should I be approaching this?

Al Avery
  • 72
  • 7
  • 3
    use `std::vector` – Brian Bi Dec 16 '16 at 00:19
  • If you don't know the required size in advance, you don't need an initialized array either. Just in the moment the array is used (i.e. some value is added) the array[i] "cell #i" is filled. If you need to read the array instead of writting on it, then you have previously added some values, don't you?. A novice approach is to use a fixed size you do know will always enough. – Ripi2 Dec 16 '16 at 00:25

0 Answers0