reinterpret_cast <double**> SEG故障

use*_*971 1 c++ pointers multidimensional-array

我正在尝试以下代码用于多维数组.它给出SEG错误我不知道这是什么问题.

 static void read(double **arr){
  //REQ arr to be pointing to  array[5][4] 
  //EFF prompt the use to input the data
  //Mod array pointer by **arr
       int i(0) , j(0);
       double tmp ;


       for(i=0 ; i<4 ; i++){

            for(j=0 ; j<5 ; j++) {
                cout <<"Please enter Data#"<<  (j+1) << " File#" << (i+1)  <<" "<<flush;

                cin >> tmp ; 
                arr[j][i] = tmp ;
            }   

        }

        return ; 
    }


int main(){
 double arr[5][4] ;
 read(reinterpret_cast<double**>(arr) ) ;
}
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

Erb*_*ica 5

您正在使用2D array的存储方式与线性数组的存储方式相同(维度仅用于索引),但您解释的是pointer to (array of) pointer(s) to (array of) double(s)具有完全不同的内存布局.看到这个这个问题.