菜鸟关于struct 在多个文件的问题

fredqfc 2005-06-22 12:59:21
SqList.h 头文件
///////////////////////////////////////////////////
#define LIST_INIF_SIZE 100
#define LIST_InCREMENT 10
typedef struct SqList
{
int* elem;
int length;
int size;
};

//typedef struct SqList SList;

void InitList(SqList &);
/////////////////////////////////

SqList.c 文件
///////////////////////////////
#include <stdio.h>
#include "SqList.h"

void InitList(struct SqList &list)
{
list.elem = (int*)malloc(LIST_INIT_SIZE * sizeof(int));
if ( !list.elem )
{

}

}
///////////////////
就到这里编译的时候错误信息:

Line1.c
e:\cproject\chap2_1\line1\sqlist.h(15) : error C2143: syntax error : missing ')' before '&'
e:\cproject\chap2_1\line1\sqlist.h(15) : error C2143: syntax error : missing '{' before '&'
e:\cproject\chap2_1\line1\sqlist.h(15) : error C2059: syntax error : '&'
e:\cproject\chap2_1\line1\sqlist.h(15) : error C2059: syntax error : ')'
e:\cproject\chap2_1\line1\line1.c(4) : error C2143: syntax error : missing ')' before '&'
e:\cproject\chap2_1\line1\line1.c(4) : error C2143: syntax error : missing '{' before '&'
e:\cproject\chap2_1\line1\line1.c(4) : error C2059: syntax error : '&'
e:\cproject\chap2_1\line1\line1.c(4) : error C2059: syntax error : ')'




...全文
237 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
fredqfc 2005-06-22
  • 打赏
  • 举报
回复
谢谢,改成* 就好了

#define LIST_INIT_SIZE 100
#define LIST_InCREMENT 10


typedef struct SqList
{
int* elem;
int length;
int size;
}SList;

//typedef struct SqList SList;

void InitList(SList *);

////////////////////////////
#include <stdio.h>
#include "SqList.h"

void InitList(SList *list)
{
list->elem = (int*)malloc(LIST_INIT_SIZE * sizeof(int));
if ( !list->elem )
{

}

}

只是将定义和实现分离才用了两个文件
zhousqy 2005-06-22
  • 打赏
  • 举报
回复
C没有引用的。
heguosheng 2005-06-22
  • 打赏
  • 举报
回复
C语言支持引用传递?
fredqfc 2005-06-22
  • 打赏
  • 举报
回复
非常谢谢
carek 2005-06-22
  • 打赏
  • 举报
回复
void InitList(struct SqList &list)
用了typedef struct SqList
struct在这里需要吗?求解
jixingzhong 2005-06-22
  • 打赏
  • 举报
回复
看楼主的程序,


提示信息中,只在和引用符号相关的地方有错!
jixingzhong 2005-06-22
  • 打赏
  • 举报
回复
晕!!


怎么这里也有C++的吗??


引用和指针略有差别,我也知道一点.

FAINT!!见笑了!!
ysbcg 2005-06-22
  • 打赏
  • 举报
回复
jixingzhong(瞌睡虫)
他写的是C++用的&操作符叫做引用
jixingzhong 2005-06-22
  • 打赏
  • 举报
回复
void InitList(SqList &)




改成void InitList(SqList *)  试试;



(如果楼主是要取地址的话)
jixingzhong 2005-06-22
  • 打赏
  • 举报
回复
typedef struct SqList{
int* elem;
int length;
int size;
}SList;


楼主的本意是这样子吧   



楼主用的是纯C吗??

我没有见过void InitList(SqList &)   这样的变量类型,

至少我看完了TC实用大全一书后,还是没有见到这样的变量类型!!
ysbcg 2005-06-22
  • 打赏
  • 举报
回复
typedef struct {
int* elem;
int length;
int size;
}SqList;
应该这么写typedef才好
或者不加typedef
conglingkaishi 2005-06-22
  • 打赏
  • 举报
回复
我想请问一下,你的typedef用来干什么的?我看不出你用它的意义啊。
kudoxinyiji 2005-06-22
  • 打赏
  • 举报
回复
用 C++ 的写法:

struct SqList
{
int* elem;
int length;
int size;
};


这样就行了。

函数声明里把 struct 去掉。

MagicCarmack 2005-06-22
  • 打赏
  • 举报
回复
你用什么环境?

hongfeeling 2005-06-22
  • 打赏
  • 举报
回复
void InitList(SqList &) 是C++的引用。C里面没有。
一般可以用指针来代替。

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧