链式表
问题在我自定义的那个函数
#include<stdio.h>
#include<stdlib.h>
const int size=20;
struct LNode *creatlist(struct LNode *l,int n);
void main(){
struct LNode{ //声明结构体
int data;
struct LNode *next;
};
}
struct LNode *creatlist(struct LNode *l,int n)
{
l=(struct LNode *)malloc(sizeof(struct LNode));
l->next=null;
for(i=n;i>0;i--)
{
struct LNode *p;
p=(struct LNode *)malloc(sizeof(struct LNode));
p->data=rand();
p->next=l->next;
l->next=p;
}
return l;
}
编绎时总是出现下面这一句:
union.cpp(31) : error C2227: left of '->next' must point to class/struct/union
但l和p明明都是指向struct LNode 的变量呀,这是我始终都想不通的地方
[解决办法]
把结构体定义在main()函数之外