我正在尝试创建一个append_node方法来将节点添加到我创建的链表中。 我的节点结构如下定义:在链表中使用结构
typedef struct Node{
struct Node next = NULL;
int id;
} Node;
然而,与下面的方法编译时,我得到以下错误: “节点”没有名为“身份证” “节点”成员没有名为“成员next'
void append_node(Node *sent,int val){
Node *other_node = (struct Node *)malloc(1*sizeof(struct Node));
other_node->id = val;
Node n = *sent;
while (n.next != NULL){
n = n.next;
}
n.next = other_node;
}
为什么会发生此错误?
编辑:
我也有以下错误
error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
的节点定义
一个'struct'无法持有相同类型的实例为本身。 – juanchopanza 2014-10-07 19:20:04
你可能的意思是:'struct Node * next = NULL;'(即缺少'*')。 – isedev 2014-10-07 19:20:48
临时'n'应该是一个指针 – sp2danny 2014-10-07 19:24:59