我对c很新,我正在尝试实现一个链表。我写了这个:
struct List;
typedef struct List* ListRef;
struct List{
void *data;
ListRef next;
ListRef last;
};
ListRef newList(void* headData);
[...]
ListRef append(ListRef list, void* data){
ListRef newlist = newList(data)
list->last->next = newList; //here I get a warning
list->last = newList; //here I get a warning
return newList;
}
newList编译时没有警告。 在我得到的评论的两行中:
警告:从不兼容的指针类型
分配我做错了什么?
谢谢!
答案 0 :(得分:2)
更改
list->last->next = newList; //here I get a warning
list->last = newList; //here I get a warning
return newList;
到
list->last->next = newlist; //here I get a warning
list->last = newlist; //here I get a warning
return newlist;
您有一个名为newList
的函数,它与您创建的结构实例(newlist
)混在一起。
你肯定不会像你是C的新手那样编码:) 希望这有帮助