typedefed结构的未知类型错误

Leo*_*do 1 c struct typedef

我正在尝试为书架制作一个链表,但是当我编译它时说

In file included from libreria.c:3:0:
libreria.h:8:2: error: unknown type name ‘Book’
  Book* next;
  ^
Run Code Online (Sandbox Code Playgroud)

就像Book没有定义一样.这是头文件

#ifndef LIBRERIA_H
#define LIBRERIA_H

typedef struct Book {
    char author[50];
    char title[50];
    int year;
    Book* next;
} Book;

void newbook(Book* book);

#endif
Run Code Online (Sandbox Code Playgroud)

问题是什么?

dbu*_*ush 6

在你的struct定义中,typedef for Book尚未定义,因此你需要struct Book在该实例中使用:

typedef struct Book {
    char author[50];
    char title[50];
    int year;
    struct Book* next;
} Book;
Run Code Online (Sandbox Code Playgroud)