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.
funcan array and not a bare pointer that you will use like an array.int &*arrrather than the unusual but validint *&arr. I've never givenint&*arrany thought - interesting to note that it is fortunately not merely a bad idea, but invalid too :-). After all, you can to something fairly equivalent via the (equally unwise)struct intRef { int & ref; intRef(int& ref):ref(ref){}}; void func(intRef * array) {}- so there's nothing fundamentally problematic with a pointer to a reference, it's just... unnecessary.