./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;
}