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


#include<iostream>
#include<conio.h>
using namespace std;
#define OK 1
#define MAXSIZE 10
#define OVERFLOW -1
#define ERROR 0
typedef int Status;
typedef  struct 
{
char  no[20];
char name[50];
float price;

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

Status   InitList(SqList L)
{
    L.elem=new ElemType[MAXSIZE];
    if(!L.elem)
        exit(OVERFLOW);
    L.length=0;
    return OK;
}
Status GetElem(SqList L ,int i,ElemType e)
{
if(i<1||i>L.length)
return ERROR;
e=L.elem[i-1];
return OK;
}
int main()
{

SqList L;
Book a;
InitList(L);
L.elem[L.length].price=0;
L.elem[L.length+1].price=1;
L.elem[L.length+2].price=2;
GetElem(L,1,a);
cout<<L.length;

cout<<L.length;
getch();


return 0;
}


我就是写个数据结构的顺序表,怎么给前三个对象的Price属性赋值,怎么运行后就溢出了呢?

Status InitList(SqList& L)
这样写
否则你初始化的是另外一个结构体,主程序没有改变
你调试下就知道,你那么写
L.elem[L.length].price=0;
这里length不是0