I am allocating memory for a 2 dimensional array as follows..how do I delete it?
double (*e)[3] = new double[4][3]
Regards
mgore
Printable View
I am allocating memory for a 2 dimensional array as follows..how do I delete it?
double (*e)[3] = new double[4][3]
Regards
mgore
I think you need to write something like this
for(int i = 0; i < 4; i++)
delete [] e[i];
delete [] e;
I am doing this but in Visual Studio while debugging I am getting a dialog box with the following message:
User breakpoint called from code at ..
A 2D array is handled internally like a 1D array, except that the compiler translates your calls to [1][5] to (max_dim*1 + 5), so to speak.
delete [] e; should actually do the trick.
Why do you not use the standard vector template instead? It is much easier and handles the memory on its own...
For further information take a look at this FAQ...
would have loved to use vector of vectors .. but the APIs which I need to call take a 2-Dimensional array of doubles, the number of columns are constrained.. and number of rows will keep varying.. so I need to allocate memory from the heap...