使用typedef结构时,错误’类型为“X *”的值无法分配给“X *”类型的实体

这是我用于节点的结构…

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

这是我用来链接它们的function

 void linkNodes(Node* first, Node* second) { if (first != NULL) first->next = second; if (second != NULL) second->previous = first; } 

现在,visual studio正在给我这些行上的intellisense(less)错误

 IntelliSense: a value of type "Node *" cannot be assigned to an entity of type "Node *" 

任何人都可以解释这样做的正确方法吗? Visual Studio将编译它并运行它查找它也可以在我的Mac上运行但是在我的学校服务器上崩溃。

编辑:我想过使用memcpy,但这很可怕

我认为问题是没有名为Node的结构 ,只有一个typedef。 尝试

  typedef struct Node { .... 

类似于Deepu的答案,但是一个允许代码编译的版本。 将结构更改为以下内容:

 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; } 

在C语言中定义struct typedef最好在struct声明本身之前完成。

 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; };