Using pointers, how would you declare a dynamic double array to the effect of:

int matrix = new int[var][var];

where var is the size of the array.

??

Printable View

- 05-27-2002InvincibleDynamic double array
Using pointers, how would you declare a dynamic double array to the effect of:

int matrix = new int[var][var];

where var is the size of the array.

?? - 05-27-2002Mario
It's quite similar to what you do to unidimensional arrays. But with a slight "problem":

Code:`int* matrix=0;`

//.. get the dimension from user input or processing (dim1)

if(!(matrix = new int[dim1][*const*]))

{

cout << endl

<< "Memory allocation failed.";

exit(1);

}

**only**specify the first dimension as a variable. All subsequent dimensions must be constants.

Also don't forget that no matter the number of dimensions, the delete statement only has one pair of square brackets:

delete [] matrix; - 05-27-2002Invincible
Yes... that was the problem I was facing. For anyone who's interested in the solution the answer is here:

http://www.cprogramming.com/cboard/s...c+double+array - 05-27-2002Mario
He! I was finding it strange someone like you making such a simple question.

Sorry for misreading your question :) - 05-27-2002Invincible
No prob Mario, you helped me realize that conventional methods weren't going to work. My thanks.