我正在嘗試創建一個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