Hello,
i have created 2D dynamic array using pointers like this:
double **matice = new double*[m];
for (int i = 0; i < m; i++) matice[i] = new double[n];
and have filled it with values. The reason i am using this
instead of vector is that i need to, its given by task and number
of columns and rows is changing due to input of user, so i need to
everytime create temporary array, pass values from original array, delete
original array, created it again and pass values from temporary array and new
ones like retard.
Thats all fine, but now i need to somehow pass this array into function
in way, that function wont be able to change values of array, make it const
(also in task). Something like this bellow, but array wont be changed.
void gauss(double **matice, int n, int m) {
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
matice[i][j] = 0;
}
}
}
int main (){
gauss (matice, n, m);
}
Thank you for any answers, if this question is stupid in any way, i am sure
someone will gladly delete it.
P.S. If there is some better solution to this dynamic array problem, i´d be glad
for help.
P.S.2. I apologize greatly for my bad Englando.
Could you show an example of when you use your variable. The code you are currently showing should work. You pass a double** to the function, this mean the pointer will be copied. This doesn't matter, since you dereference it (twice actually), yielding the same memory location you modify. The problem doesn't appear to be in your current code. Of course, I could be missing something.
Should it not be able to change the actual values, because in that case the loop setting the entire array to 0 will not compile. Or should it not be able to change the pointers?