struct student
{
char name[8];
char sex[2];
int num;
};
student stu[3]; //还是用student* stu[3];为什么?
for(int i=0; i<3; i++)
stu[i] = new student;
stu[0]->num = 0;
为什么?因为你需要的是一个指针数组,也就是说str[0],str[1],str[2]都是指针
struct student
{
char name[8];
char sex[2];
int num;
};
student * stu[3];
for(int i=0; i<3; i++)
stu[i] = new student;
stu[0]->num = 0;
new student返回的是一个指针
new返回的是指针
所以****
我刚开始学NEW时,也搞错过
呵呵
是student *stu[3];
实际上定义一个对象指针。
应该是student *stu[3];
如果你用student stu[3];的话,那你就要这样了:stu[0].num = 0;