簡體   English   中英

來自c中不兼容指針類型的賦值,用於指向struct的指針

[英]assignment from incompatible pointer type in c, for a pointer to struct

我對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編譯時沒有警告。 在帶有注釋的兩行中,我得到:

警告:從不兼容的指針類型分配

我究竟做錯了什么?

謝謝!

更改

    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一樣陌生。:)希望這會有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM