I have a function which takes as input, a pointer to a 2D array, and a pointer to a 1D array.
int resize(double *x, double **y, int n){
The aim of this function is to resize both x and y to be twice their length (n).
I create two new arrays- which have been doubled in length
double **yTemp = NULL;
double *xTemp = NULL;
xTemp = new double[2*n + 1];
yTemp = new double*[2*n + 1];
I then loop through and replace the values of xTemp with and yTemp with x and y
After then setting them equal to one other:
y = yTemp;
x = xTemp;
return 2*n;
and exiting the function, y and x seem to lose the extra length.
Any help on this would be great!
free[]the old values. (But why not use vectors and avoid all this complex, fragile nonsense?)yTemp, however, you probably don't want to delete the inner elements because they'll be part of the expanded array (perhaps, it depends on your exact implementation). But please, just use something likestd::vector.