Hello David,
 
There are 2 ways to do this.
 
1. If we have to fix any one of the array dimension at the declaration itself then the array declaration and allocation will looks like this.
 
const int n = 1024;
int a;
cout << "Enter the value of a: ";
cin >> a;
int (*nArray)[n];   /*declaration*/
nArray = new int[a][n]   /*definition*/
 
2. If array dimensions are unknown
 
int a, b;
 
int **nArray;  /*declaration*/
cout << "Enter the value of a:";
cin >> a;
count << "Enter the value of b:";
cin >> b;
/*definition*/
nArray = new int*[a];
for (int i = 0; i < a; i++)
    nArray[i] = new int[b];
 
I think this is what you are looking for. I know only the above methods to initialize a 2-dimensional array dynamically. Hope some of this helps you.
 
Good Luck & Happy Programming.
 
Sreeram.
----- Original Message -----
Sent: Thursday, April 24, 2003 5:51 AM
Subject: [msvc] dynamically allocated multi-dimensional array

I need to allocate an array of ints dynamically.

I want to do something like:

m_pint = new int [100][100];

What is the correct definition of m_pint so that the above code will compile?

TIA

Best regards,
David Stroupe
Keyed-Up Software
5307 Faireast Court
Arlington, Texas 76018-1683
817/557-4903 voice
817/472-0408 fax

Reply via email to