qq_43412960 2019-12-22 23:02 采纳率: 78.6%
浏览 212
已结题

这是我写关于数据结构链表初始化功能的一个代码


#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(List *L)
{
  L=new List();
  if(!L)
      exit(-1);
  else
     (*L).next=NULL;
  return OK;
}

int main()
{
LNode L;
L.Elem.price=1;
List * LL;



getch();


return 0;
}


为什么会报错
--------------------Configuration: 线性表 - Win32 Debug--------------------
Compiling...
线性表.cpp
E:\数据结构\线性表.cpp(29) : error C2228: left of '.next' must have class/struct/union type
Error executing cl.exe.

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

大概是
(*L).next=NULL;
出了问题。我很纳闷,*L整体是个值结构体类型,给地址赋值,这么写没有问题啊

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-12-23 09:44
    关注
    (*L)->next=NULL;
    或者
    (**L).next=NULL;
    
    因为 
    typedef  struct  LNode 
    {
    Book Elem;
    LNode *next;
    
    }LNode,*List;
    List已经是指针了,所以L是指针的指针,而*L是指针,所以用->
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题