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

后端 未结 3 757
走了就别回头了
走了就别回头了 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 09:55

    Similar to Deepu's answer, but a version that will let your code compile. Change your struct to the following:

    typedef struct Node // <-- add "Node"
    {
        struct Node* next;
        struct Node* previous;
        void* data;
    }Node; // <-- Optional
    
    void linkNodes(Node* first, Node* second)
    {    
        if (first != NULL)
            first->next = second;
    
        if (second != NULL)
            second->previous = first;
    }
    

提交回复
热议问题