I'm trying to pass a struct with 2d array pointers into a function which would change the values specific cells in the array. refer to the sample code:
void link_list( part_pairs *y...... ) // pointers were created in prior funct
{ int i, n_allocate = 60;
y->pairs = newint*[n_allocate];
for (i = 0; i < n_allocate; ++i) y->pairs[i] = newint[n_cp]();
y->dis_pair = newdouble*[n_allocate];
for (i = 0; i < n_allocate; ++i) y->dis_pair[i] = newdouble[n_cp]();
y->h_pair = newdouble*[n_allocate];
for (i = 0; i < n_allocate; ++i) y->h_pair[i] = newdouble[n_cp]();
y->k_pair = newdouble*[n_allocate];
for (i = 0; i < n_allocate; ++i) y->k_pair[i] = newdouble[n_cp]();
y->g_pair = newdouble*[n_allocate];
for (i = 0; i < n_allocate; ++i) y->g_pair[i] = newdouble[n_cp]();
**** other codes not involving y ****
for (lz = 1; lz < (ncz + 1); lz++){
for (ly = 1; ly < (ncy + 1); ly++){
for (lx = 1; lx < (ncx + 1); lx++){
j1 = lx + (ly - 1)*ncx + (lz - 1)*nsheet;
cell(y, j1,...); // function cal; unable to use "&y"
}
}
}
return;
} // end function link_list
> The code is truncated to the gist, I hope it's sufficient information to
> advise me on what i should modify.
those snips don't compile, so can't run the program and input whatever it needs to shows the wrong output (which also don't know what should be).
It should be able to reproduce the exact same problem that you're having, anything less than that is useless.
> cell(y, j1,...); // function cal; unable to use "&y"
don't fall on the «doesn't work, add or remove * or &» vudú.
I would change the y parameter in link_list() and cell() to be a reference instead of a pointer. Don't pass a pointer unless you expect that it can be null.
In cell(), what is the value of npairs[i][i]? I suspect they aren't what you think. Try examining the value of the arrays before you return from link_list().