Error 'a value of type “X *” cannot be assigned to an entity of type “X *”' when using typedef struct

后端 未结 3 777
走了就别回头了
走了就别回头了 2021-01-21 09:11

Here is the struct I am using for the nodes...

typedef struct
{
    struct Node* next;
    struct Node* previous;
    void* data;
} Node;

and h

3条回答
  •  無奈伤痛
    2021-01-21 10:10

    Defining typedef of struct in C is best done before the struct declaration itself.

    typedef struct Node Node; // forward declaration of struct and typedef
    
    struct Node
    {
        Node* next;          // here you only need to use the typedef, now
        Node* previous;
        void* data;
    };
    

提交回复
热议问题