Return struct of multi-array from user-defined function in C++

  allocation, arrays, c++, memory, struct

I wrote a function as below, declared a struct of 2D array. size of this struct is initialized in function read_landmask.

struct landmask {
    double value;
};
landmask read_landmask(NcFile &dataFile,grid grid, parameters params) {
NcVar lm;
...
  size_t m=grid.lat.size();
  size_t n=grid.lon.size();

  landmask lmdomain[m][n];

  for (int i=0;i<m;++i){
    for (int j=0;j<n;++j){
      neighborpoints nbpoints=closest_distance(lmbnds.sizelat,lmbnds.sizelon,*lmdata, lmbnds.lat,lmbnds.lon, grid.lat[i], grid.lon[j]);
      lmdomain[i][j].value=interp2D_Cressman(nbpoints.lon, nbpoints.lat,nbpoints.val, grid.lat[i], grid.lon[j]);
    }
  };

  return lmdomain[m][n];
};

and in the main function, it is called like:

int main(){
landmask landmask_array=read_landmask(lmfile,grid,params);
cout<< landmask_array[3][2].value<< endl;
};

but the cout is error. Seems like the array is not return the whole 2D array, so I cannot put the indices of rows and columns.
Does anyone have ideas or experiences with this before?
Thanks

Source: Windows Questions C++

LEAVE A COMMENT