I’m trying to create an object array and it works just fine if I enter the array size manually, but whenever it tries to get the infromation from the function args it gives the errors “Expected constant expression” and “cannot allocate an array of constant size 0”.
I’ve searched around and found multiple solutions but none of them works for me. Code currently looks like this:
Array::Array(int in, int min, int max)
{
size = in;
Heltal *htal[size];
}
The size integer and htal object is defined in the header file.
The line that seems to be causing the problem is the last one.
Whats causing this and how do I fix it?
VLAs (variable length arrays) are not supported in C++. Even if they were,
ais avectorsoHeltal *htal[a];doesn’t make sense.You fix this by using an
std::vectorinstead of an array (of a valid size):