[英]Error 'a value of type “X *” cannot be assigned to an entity of type “X *”' when using typedef struct
这是我用于节点的结构...
typedef struct
{
struct Node* next;
struct Node* previous;
void* data;
} Node;
这是我用来链接它们的功能
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;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.