作者:张骞2502860155 | 来源:互联网 | 2023-05-17 09:03
这是实现顺序表的初始化c程序:
#include "stdio.h"
#include "stdlib.h"
#define OVERFLOW 0
#define OK 1
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct {
int *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList *L);
int main()
{
SqList L;
InitList_Sq(SqList &L);
system("pause");
return 0;
};
int InitList_Sq(SqList *L)
{
L->elem = (int *)malloc(LIST_INIT_SIZE * sizeof(int));
if(!L->elem) exit(OVERFLOW);
L->length = 0;
L->listsize = LIST_INIT_SIZE;
return OK;
}
其中 InitList_Sq(SqList &L); 出错:
--------------------Configuration: 线性表的顺序表示 - Win32 Debug--------------------
Compiling...
线性表的顺序表示.cpp
F:\MyProject\线性表的顺序表示\线性表的顺序表示.cpp(22) : error C2275: 'SqList' : illegal use of this type as an expression
F:\MyProject\线性表的顺序表示\线性表的顺序表示.cpp(14) : see declaration of 'SqList'
Error executing cl.exe.
线性表的顺序表示.obj - 1 error(s), 0 warning(s)
如果把 InitList_Sq(SqList &L); 改为 InitList_Sq(&L); 后编译就不会出错,这是为什么呢?
6 个解决方案