T **AllocateDynamicArray( int nRows, int nCols)
{
T **dynamicArray;
dynamicArray = new T*[nRows];
for( int i = 0 ; i < nRows ; i++ )
dynamicArray[i] = new T [nCols];
return dynamicArray;
}
template
void FreeDynamicArray(T** dArray)
{
delete [] *dArray;
delete [] dArray;
}
int main()
{
int **my2dArr = AllocateDynamicArray
my2dArr[0][0]=5;
my2dArr[2][2]=8;
cout << my2dArr[0][0] << " "<
cout << my2dArr[1][1] << " "<
FreeDynamicArray
getch();
return 0;
}
Similarly for 3 d array: