c - typedefed 结构的未知类型错误

标签 c struct typedef

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

In file included from libreria.c:3:0:
libreria.h:8:2: error: unknown type name ‘Book’
  Book* next;
  ^

就像没有定义 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

问题是什么?

最佳答案

在您的结构定义中,尚未定义 Book 的类型定义,因此您需要在该实例中使用 struct Book:

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

关于c - typedefed 结构的未知类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32333349/

相关文章:

c - 是什么导致了堆栈溢出?我该如何解决它?

c++ - 如何监视哪些进程访问 Unix 中的特定文件?

c - C中结构的不同语法

c - 如何打印指针的指向值?

c - 这个数组是静态的还是动态的?

c - 使用结构体的函数会导致段错误

c - 如何计算结构上的 crc16

c++ - sizeof(streamsize) 使用 Visual Studio 2012

链接静态库时,typedef 结构会导致名称冲突吗?

c++ - 如何对通过几层模板派生的类型进行typedef?