#include
using namespace std;
#include<string.h>
#include<malloc.h>
typedef struct node
{
string no;
string name;
double prize;
}Node;
typedef struct abc
{
Node data;
Node *next;
}pNode,*PNode;
void creat_list(PNode pL);
void input_list(PNode pL);
int main()
{
pNode L;
creat_list(&L);
input_list(&L);
}
void creat_list(PNode pL)
{
pL=(PNode)malloc(sizeof(pNode));
if(pL==NULL)
{
cout<<"分配内存失败"<<endl;
exit(-1);
}
pL->next=NULL;
}
void input_list(PNode pL)
{
PNode pS=(PNode)malloc(sizeof(pNode));
if(pS==NULL)
{
cout<<"分配内存失败"<<endl;
exit(-1);
}
pS=pL;
for(int i=0;;i++)
{
PNode newNode=(PNode)malloc(sizeof(pNode));
if(newNode==NULL)
{
cout<<"分配内存失败"<<endl;
exit(-1);
}
cin>>newNode->data.name>>newNode->data.no>>newNode->data.prize;
pS->next=newNode;
pS=newNode;
if(newNode->data.prize==0)
{
break;
}
}
}
错误地方: pS->next=newNode;
错误原因:[ error ]无法在赋值中将‘ pnode { aka abc * }’转换为‘ node * { aka node * }’
求大佬解答
试试:
pS->next=*newNode;
next是Node *类型,但是你这里赋值的PNode类型
typedef struct abc
{
Node data;
abc *next; //c的话要在前面加上struct,是c++的话就不用
}pNode,*PNode;