这是一个关于数据结构线性表的问题


#include<iostream>

using namespace std;
#define OK 1
#define MAXSIZE 10000
#define OVERFLOW -1

int main()
{

typedef  struct 
{
char  no[20];
char name[50];
float price;

}Book;
typedef  struct
{
Book *elem;
int length;
}SqList;
SqList L;

return 0;
}
int a(SqList L)
{
    return OK;
}

上面是我写的代码,编译后
--------------------Configuration: 线性表 - Win32 Debug--------------------
Compiling...
线性表.cpp
E:\数据结构\线性表.cpp(24) : warning C4101: 'L' : unreferenced local variable
E:\数据结构\线性表.cpp(28) : error C2065: 'SqList' : undeclared identifier
E:\数据结构\线性表.cpp(28) : error C2146: syntax error : missing ')' before identifier 'L'
E:\数据结构\线性表.cpp(28) : error C2059: syntax error : ')'
E:\数据结构\线性表.cpp(29) : error C2143: syntax error : missing ';' before '{'
E:\数据结构\线性表.cpp(29) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

线性表.exe - 5 error(s), 1 warning(s)
显示上述错误,为什么呢?

你的写法很奇怪,一般来说,结构体的定义应该放在函数的定义之外。

#include<iostream>

using namespace std;
#define OK 1
#define MAXSIZE 10000
#define OVERFLOW -1
typedef  struct 
{
char  no[20];
char name[50];
float price;

}Book;
typedef  struct
{
Book *elem;
int length;
}SqList;
int a(SqList L);
int main()
{
SqList L;
a(L);
return 0;
}
int a(SqList L)
{
    return OK;
}

这样才make sense

Book和SqList定义在main函数里面,所以作用域只限于main函数,到a函数的位置当然是未定义了。把typedef struct的这两个定义移到main函数之前。