【发布时间】:2015-02-28 07:25:28
【问题描述】:
我无法找到我的错误。这是structures.h中的定义
typedef struct book {
bank_account_t **accounts;
transaction_t **transactions;
} book_t;
这里是functions.c,我在其中包含标题并尝试使用类型book_t
#include "structures.h"
void load_book(book_t *book) {
}
但我收到此错误
functions.c:10:16: error: unknown type name ‘book_t’
void load_book(book_t *book) {
^
使用以下更多代码进行编辑:
在我的main 文件中,我像这样订购了我的.h 文件
#include "structures.h"
#include "functions.h"
structures.h
#ifndef STRUCTURES_H
# define STRUCTURES_H
typedef struct bank_account {
char *name;
int amount;
} bank_account_t;
typedef struct transaction {
char *name;
int amount;
} transaction_t;
typedef struct book {
bank_account_t **accounts;
transaction_t **transactions;
} book_t;
#endif
function.c
#include <stdio.h>
#include "functions.h"
#include "structures.h"
#include "bank_account.h"
#include "transaction.h"
void load_book(book_t *book) {
}
void init_book() {
}
bank_account.h
#ifndef BANK_ACCOUNT_H
# define BANK_ACCOUNT_H
void init_new_bank();
void deinit_new_bank();
#endif
transaction.h
#ifndef TRANSACTION_H
# define TRANSACTION_H
#endif
【问题讨论】:
-
不是 book_t 仅在结构中有效吗?
-
您可能从您使用的另一个头文件中复制粘贴了头文件,却忘记调整头文件保护?
-
出于调试目的,在
book_t的定义之后的行中包含一个#error choke或只是一些垃圾,并查看编译器是否会阻塞它。 -
All downvoters:这是一个初学者的调试问题。所以很难提供更多信息,因为如果 OP 知道在哪里看,他/她就不会来这里了。
-
请同时显示functions.h
标签: c types header-files