ファイルから標高値を2次元配列と行列に読み込み、その配列を別の関数に渡そうとしているプログラムで作業しています最大値。私は、デフォルトで配列が参照渡しされることを理解していますが、関数の配列の値を変更しようとしていないので、これはあまり重要ではありません。私は配列を呼び出すことに関するいくつかのページを見てきましたが、私はコードをコンパイルするときに私が得ているエラーのタイプの言及を見つけることができませんでした。この問題は、呼び出される引数の数や呼び出される方法にあるように思われますが、関数のさまざまな外観には矛盾が見られません。私の推測では、2次元配列を渡すことについて何かがあります。私はクラスでは言わなかったし、自分ではまだ学習していないということです。どんな助けでも大歓迎です。 コードは次のとおりです。二次元配列を二重に渡す際のエラーfunction_name
はエラー:ダブル(*)[(((ロングunsigned int型)(((長い」変換することはできません
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
// First instance of function declaration
double find_max(double elevations[][3600], double ilat, double ilon, int nlat, int nlon);
int main(int argc, char *argv[]) {
// Declare program variables
double lat_init, lon_init;
double lat_res, lon_res;
double peak, valley;
int lon_col, lat_row;
string indat, inpoints;
.
.
.
double elevations[lat_row][lon_col];
// Open and read topographic data file
ifstream topo_points;
topo_points.open(inpoints.c_str());
for (int i=0; i<lat_row; i++) {
for (int j=0; j<lon_col; j++)
topo_points >> elevations[i][j];
}
// Call function to find peak in the data
peak = find_max(elevations, lat_init, lon_init, lat_row, lon_col);
return 0;
}
// ***** Here lie the functions *****
// This function reads in the array of elevations, initial latitude and longitude
// of the data, and the number of data points and uses this information to find
// the latidude and longitude of the highest point on earth
double find_max(double elev[][3600], double ilat, double ilon, int nlat, int nlon) {
double num, max;
double latpos, lonpos;
max = 0;
for (int i=0; i<nlat; i++) {
for (int j=0; j<nlon; j++) {
num = elev[i][j];
if (num > max) {
max=num;
latpos= ilat - i;
lonpos= ilon + j;
}
}
}
cout << "The tallest peak on earth has an altitude of " << max;
cout << " and is located at " << latpos << "deg latitude and ";
cout << lonpos << "deg longitude";
return max;
}
しかし、私は次のエラーを取得する関数を呼び出すとき'double'(double(*)[3600]、double、double、int、int) 'に' 1 'を指定するとdouble(*)[3600]
lon_col = 3600ですか? – tmpearce