c++用new申请构造内存
c++用new申请结构内存
struct stu{
char key[10];
char name[20];
int age;
};
struct snext{
stu sdata;
snext *nextstu;
};
snext * add(snext * head,stu sdata){
snext *node,*htemp;
if((node=new snext)=NULL){
cout<<"shengqing shibai";
return NULL;
}else{
node->sdata =sdata; //显示这个地方写入冲突,求解
node->nextstu =NULL;
...
}
}
运行之后会显示写入位置冲突
------解决思路----------------------
(node=new snext)==NULL
struct stu{
char key[10];
char name[20];
int age;
};
struct snext{
stu sdata;
snext *nextstu;
};
snext * add(snext * head,stu sdata){
snext *node,*htemp;
if((node=new snext)=NULL){
cout<<"shengqing shibai";
return NULL;
}else{
node->sdata =sdata; //显示这个地方写入冲突,求解
node->nextstu =NULL;
...
}
}
运行之后会显示写入位置冲突
------解决思路----------------------
(node=new snext)==NULL