我有這個結構:
typedef struct {
int id;
node_t * otherNodes;
} node_t;
我的節點中需要一個節點陣列....
但在頭檔案中無法識別:它告訴我`未知型別名稱'node_t'
我該如何解決這個問題?
謝謝
uj5u.com熱心網友回復:
在這個 typedef 宣告中
typedef struct {
int id;
node_t * otherNodes;
} node_t;
名稱node_t結構定義內,未宣告的名稱。所以編譯器會報錯。
你需要寫例如
typedef struct node_t {
int id;
struct node_t * otherNodes;
} node_t;
或者你可以寫
typedef struct node_t node_t;
struct node_t {
int id;
node_t * otherNodes;
};
甚至喜歡
struct node_t typedef node_t;
struct node_t {
int id;
node_t * otherNodes;
};
uj5u.com熱心網友回復:
我參考了struct list_head內核代碼的定義:https :
//git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/types.h?h=v5.10.84# n178
所以我會這樣寫:
struct node {
int id;
struct node * otherNodes;
};
typedef struct node node_t;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/379866.html
下一篇:如何在正方形內找到公共區域
