Home > Back-end >  Save the children, bothering me for a long time, the dynamic structure arrays, why show_person funct
Save the children, bothering me for a long time, the dynamic structure arrays, why show_person funct

Time:03-16

#include
#include
#include
using namespace std;
Struct student
{
String m_name;
Int m_sex;
Int m_age;
};
Struct adminstudent
{
The data struct student * *;
Int m_size;
};
Void add_person (struct adminstudent * p)
{
int n;
String name;
Int sex, the age;
Cout & lt; <"The number of people you want to add" & lt; Cin & gt;> n;
Int newsize=n + p - & gt; M_size;
Newspace struct student * *=NULL;
Newspace=new struct student * [newsize];
for (int i=0; I & lt; P - & gt; M_size; I++)
{
Newspace [I]=p - & gt; Data [I];
}
For (int I=p - & gt; M_size; I & lt; Newsize; I++)
{
Newspace [I]=NULL;
Newspace [I]=new struct student ();
Cout & lt; <"Gender" & lt; Cin & gt;> Sex;
Newspace [I] - & gt; M_sex=sex;
Cout & lt; <"Name" & lt; Cin & gt;> The name;
Newspace [I] - & gt; M_name=name;
Cout & lt; <"Age" & lt; Cin & gt;> The age;
Newspace [I] - & gt; M_age=age;
The delete newspace [I];
}
The delete [] p - & gt; data;
P - & gt; Data=https://bbs.csdn.net/topics/newspace;
The delete [] newspace;
P - & gt; M_size=newsize;
}
Void show_person (struct adminstudent * p)
{
int i;
For (I=0; I & lt; P - & gt; M_size; I++)
{
Cout & lt;

Cout & lt;

Cout & lt;

}
}
Int main ()
{
Struct adminstudent * p=new struct adminstudent ();
P - & gt; M_size=0;
P - & gt; Data=https://bbs.csdn.net/topics/NULL;
Add_person (p);
Show_person (p);
The delete p;
}

CodePudding user response:

Delete the following two lines:
The delete newspace [I];
The delete [] newspace;

CodePudding user response:

reference 1st floor coo135 response:
delete the following two lines:
The delete newspace [I];
The delete [] newspace;

Can you explain why the second to delete  , bosses for help
  • Related