0
./product -rows 4 -cols 4
我得到這個錯誤:中止(轉儲核心)
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Abort (core dumped)
這是我的代碼..
#include <iostream>
#include <stdlib.h>
using namespace std;
int **create_array(int rows, int cols){
int x, y;
int **array = new int *[rows];
for(int i = 0; i < cols; i++){
array[i] = new int[cols];
}
array[x][y] = 1+rand()%100;
cout << array << endl;
return array;
}
int main(int argc, char *argv[]){
int rows, cols;
int **my_array = create_array(rows, cols);
return 0;
}