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


#include<iostream>
#include<conio.h>
#include<string.h>
#define OK 1
#define MAXSIZE 100
using namespace std;
typedef  int Status;
#define OK 1
typedef  struct  
{
char name[5];
float price;    
}Book;

typedef  struct  LNode 
{
Book Elem;
LNode *next;

}LNode,*List;

Status InitList(LNode *L)
{
  L=new LNode();
  if(!L)
      exit(-1);
  else
    L->next=NULL;
  return OK;
}

int main()
{
LNode *L;

List LL;
InitList(L);
cout<<(*L)->next;
getch();


return 0;
}


我仅仅完成了链表的初始化,为啥报错呢?
--------------------Configuration: 线性表 - Win32 Debug--------------------
Compiling...
线性表.cpp
E:\数据结构\线性表.cpp(39) : error C2819: type 'LNode' does not have an overloaded member 'operator ->'
E:\数据结构\线性表.cpp(17) : see declaration of 'LNode'
E:\数据结构\线性表.cpp(39) : error C2227: left of '->next' must point to class/struct/union
Error executing cl.exe.

线性表.exe - 2 error(s), 0 warning(s)

cout<<(*L)->next;这一行错了,指针变量的用法是直接p->x就可以了,这行改成cout<< L->next;
还有指针变量在使用时最好初始化,LNode *L;最好改成LNode *L=NULL;

你可以参考:
https://ask.csdn.net/questions/1045910