![](/img/trans.png)
[英]Declare struct type, insert values into array of the type, and print out array
[英]declare element in array that is the struct type
我有这个结构:
typedef struct {
int id;
node_t * otherNodes;
} node_t;
我的节点中需要一个节点数组....
但在 header 文件中无法识别:它告诉我`未知类型名称'node_t'
我该如何解决这个问题?
谢谢
在这个 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;
};
I referenced defenition of struct list_head
from kernel codes: 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.