0
我有循環依賴的代碼。解決循環typedef依賴性的正確方法是什麼?
老A.H文件:
#ifndef A_H
#define A_H
#include "b.h"
typedef struct {
b_t *test;
} a_t;
#endif
老b.h文件:
#ifndef B_H
#define B_H
#include "a.h"
typedef struct {
a_t *test;
} b_t;
#endif
我只是想知道,如果我的解決方案是 「適當的方式」 來解決這個問題。我想生成漂亮而清晰的代碼。
新A.H文件:
#ifndef A_H
#define A_H
#include "b.h"
typedef struct b_t b_t;
struct a_t {
b_t *test;
};
#endif
新b.h文件:
#ifndef B_H
#define B_H
#include "a.h"
typedef struct a_t a_t;
struct b_t {
a_t *test;
};
#endif
谷歌的「不完整的類型」。 – wildplasser 2012-02-23 11:38:06
有一個參數用於使用結構而不是使用typedefs混淆代碼。 – 2012-02-23 13:19:09