#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;
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;
Newspace [I] - & gt; M_sex=sex;
Cout & lt; <"Name" & lt;
Newspace [I] - & gt; M_name=name;
Cout & lt; <"Age" & lt;
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: