c++ dynamic size of the array
arrays, c++, dynamic
Solution
Use a pointer, not a reference:
void func(int *a, int N);
Or, easier, use a vector:
void func(std::vector<int> &a);
Vectors can be allocated by simply saying
std::vector<int> a(10);
The number of elements can be retrieved using `a.size()`.
Problem
I have got a small problem with 1D array in c++. I have got a function line this: ``` void func(int (&array)[???]) { // some math here; "for" loop { array[i] = something; } } ``` I call the functions somewhere in the code, and before I made math I'm not able to know dimension of the array. The array goes to the function as a reference!, because I need it in the main() function. How I can allocate array like this?, so array with ?? dimension goes to the function as reference then I have to put the dimension and write to it some values.