p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Ivor Horton's Beginning Visual C++ 2010 (http://p2p.wrox.com/forumdisplay.php?f=569)
-   -   How to use multidimensional dynamic array (http://p2p.wrox.com/showthread.php?t=94907)

flyingba August 30th, 2015 11:35 PM

How to use multidimensional dynamic array
 
When develop a program which uses the 5-dimensions dynamic array, meet the problem.

The compile process is OK. During running ,the message "IIIIIIIIIIIII" appears, but the message "JJJJJJJJJJJJJJJJJJJ" does not appear. Instead ,the following warning appears:


Debug Assertion Failed!


What causes this problem? How to solve this problem.

Anybody could help me?

Thanks.




The following is the code:

void CTestDynamicArrayDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
int N1=5;
int N2=5;
int N3=5;
int N4=5;
int N5=5;

double *****A1,*****A2;
double *****A3,*****A4;
double *****A5;

A1=new double****[N1];
A2=new double****[N1];
A3=new double****[N1];
A4=new double****[N1];
A5=new double****[N1];
for (int i=0;i<N1;i++)
{
A1[i]=new double***[N2];
A2[i]=new double***[N2];
A3[i]=new double***[N2];
A4[i]=new double***[N2];
A5[i]=new double***[N2];
}
for (int i=0;i<N1;i++)
for (int j=0;j<N2;j++)
{
A1[i][j]=new double**[N3];
A2[i][j]=new double**[N3];
A3[i][j]=new double**[N3];
A4[i][j]=new double**[N3];
A5[i][j]=new double**[N3];
}
for (int i=0;i<N1;i++)
for (int j=0;j<N2;j++)
for (int p=0;p<N3;p++)
{
A1[i][j][p]=new double*[N4];
A2[i][j][p]=new double*[N4];
A3[i][j][p]=new double*[N4];
A4[i][j][p]=new double*[N4];
A5[i][j][p]=new double*[N4];
}
for (int i=0;i<N1;i++)
for (int j=0;j<N2;j++)
for (int p=0;p<N3;p++)
for (int q=0;q<N4;q++)
{
A1[i][j][p][q]=new double[N5];
A2[i][j][p][q]=new double[N5];
A3[i][j][p][q]=new double[N5];
A4[i][j][p][q]=new double[N5];
A5[i][j][p][q]=new double[N5];
}




for (int i=0;i<N1;i++)
for (int j=0;j<N2;j++)
for (int p=0;p<N3;p++)
for (int q=0;q<N4;q++)
for (int r=0;r<N5;r++)
{
A1[i][j][p][q][r]=0;
A2[i][j][p][q][r]=0;
A3[i][j][p][q][r]=0;
A4[i][j][p][q][r]=0;
A5[i][j][p][q][r]=0;
}





for (int i=0;i<N1;i++)
for (int j=0;j<N2;j++)
for (int p=0;p<N3;p++)
for (int q=0;q<N4;q++)
{
delete[] A1[i][j][p][q];
delete[] A2[i][j][p][q];
delete[] A3[i][j][p][q];
delete[] A4[i][j][p][q];
delete[] A5[i][j][p][q];
}
AfxMessageBox(_T("GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GGGGGGGGGGGGGGGG"));
for (int i=0;i<N1;i++)
for (int j=0;j<N2;j++)
for (int p=0;p<N3;p++)
{
delete[] A1[i][j][p];
delete[] A2[i][j][p];
delete[] A3[i][j][p];
delete[] A4[i][j][p];
delete[] A5[i][j][p];
}
AfxMessageBox(_T("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHH"));
for (int i=0;i<N1;i++)
for (int j=0;j<N2;j++)
{
delete[] A1[i][j];
delete[] A2[i][j];
delete[] A3[i][j];
delete[] A4[i][j];
delete[] A5[i][j];
}
AfxMessageBox(_T("IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIIII"));
for (int i=0;i<N1;i++)
{
delete[] A1[i];
delete[] A1[i];
delete[] A3[i];
delete[] A3[i];
delete[] A5[i];
}
AfxMessageBox(_T("JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ JJJJJJJJJJJJJJJJJJJ"));
delete[] A1;
delete[] A2;
delete[] A3;
delete[] A4;
delete[] A5;
AfxMessageBox(_T("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKKKKKKKK"));


}


All times are GMT -4. The time now is 06:08 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.