View Single Post
  #1 (permalink)  
Old August 30th, 2015, 11:35 PM
flyingba flyingba is offline
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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"));


}