pointer to incomplete class type is not allowed - singly linked list

前端 未结 1 799
囚心锁ツ
囚心锁ツ 2021-01-26 22:19

I\'m trying to create a simple singly linked list. Previously, I successfully did this with no errors, however now I encounter an error. I suspect that there is some kind of pro

1条回答
  •  执笔经年
    2021-01-26 22:50

    typedef struct
    {
    } Product;
    

    Declares a type alias called Product for an unnamed struct - however you need a named struct for your forward declaration struct Product *next;, otherwise the compiler cannot determine which definition it belongs to.

    The simplest solution is to give the struct a name:

    typedef struct Product
    {
        int value;
        struct Product *next;
    } Product;
    

    0 讨论(0)
提交回复
热议问题