首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

链式表,该怎么解决

2013-01-02 
链式表问题在我自定义的那个函数#includestdio.h#includestdlib.hconst int size20struct LNode *cr

链式表

问题在我自定义的那个函数

#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()函数之外

热点排行