2016-04-28 11 views
1

私は互いに参照する必要がある構造体を2つ持っていますが、未確認の型を使用しているため最初にスローしてエラーを出します。お互いを参照する構造体

typedef struct _BLOCK 
{ 
    int size; 
    int offset; 
    struct _BLOCK *nextBlock; 
    struct _BLOCK *prevBlock; 
    Pool* parent; //here 
} Block; 

typedef struct _POOL 
{ 
    int size; 
    void* memory; 
    Block* Allocated; 
    Block* Unallocated; 
} Pool; 

これを解決する方法はありますか?

+2

「_」で始まり大文字またはアンダースコアで始まる名前は、実装用に予約されています。 **それらを使用しないでください**。 – Olaf

答えて

4

フォワード宣言を使用できます。

typedef struct _POOL Pool; 

typedef struct _BLOCK 
{ 
    int size; 
    int offset; 
    struct _BLOCK *nextBlock; 
    struct _BLOCK *prevBlock; 
    Pool* parent; 
} Block; 

struct _POOL 
{ 
    int size; 
    void* memory; 
    Block* Allocated; 
    Block* Unallocated; 
}; 
+0

非常に役に立ちました、歓声 – David

関連する問題