我无法找到我的错误。这是 structurals.h
中的定义
typedef struct book {
bank_account_t **accounts;
transaction_t **transactions;
} book_t;
这里是在functions.c
中,我包含 header 并尝试使用类型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"
结构.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
交易.h
#ifndef TRANSACTION_H
# define TRANSACTION_H
#endif
最佳答案
我认为问题一定出在functions.h中(原帖中没有包含它)。
functions.h
#ifndef FUNCTIONS_H
# define FUNCTIONS_H
/* [MarkU] required: include definition of book_t */
#include "structures.h"
void load_book(book_t *book);
void init_book();
#endif
如果没有#include Structures.h
,就没有 boot_t 类型的定义。
使用 mingw32-gcc 4.7.2 构建并验证。省略#include,我看到了错误消息。
关于c - 这有什么问题吗? C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28779263/