新矩阵[N] [N]失败 [英] new matrix[N][N] failure
本文介绍了新矩阵[N] [N]失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个堆栈溢出在堆栈上分配一个巨大的矩阵(我同意:它很愚蠢的分配它),我写下面的代码,因为我想访问矩阵的元素与下标indices mat [x] [y]
double(* mul1)[N] [N]
mul1 = new double [N] [N];
我收到一个错误:
错误C2440:'=':无法从'double(*)[1000]'转换为double(*)[1000] [1000]'
为什么我不能用新的分配一个二维数组?
解决方案
double * mul1 [N];
for(int i = 0; imul1 [i] = new double [N];
I'm having a stack overflow allocating a huge matrix on the stack (and I agree with that: it's stupid to allocate it there) and I'm writing the following code since I want to access the matrix's elements with the subscripts indices mat[x][y]
double (*mul1)[N][N]; mul1 = new double[N][N];
I'm receiving an error:
error C2440: '=' : cannot convert from 'double (*)[1000]' to 'double(*)[1000][1000]'
Why can't I allocate a bidimensional array with new?
解决方案double *mul1[N]; for (int i=0;i<N;++i) mul1[i] = new double[N];
Representing a 2D array as a 1D array
Performance of 2-dimensional array vs 1-dimensional array
这篇关于新矩阵[N] [N]失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文