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];
and you avoid the pointer indirection that appears in the linked question for the nested arrays. (The key is that the*
replaces one of the[]
, andnew T[]
returns a pointer to the first element.) Or you can writeunique_ptr<double[][N]> mul1(new double[N][N]);
and get automatic cleanup.