很长一段时间以来,我一直试图让一个指针与另一个指针相等,但它不会这样做,而且我不确定为什么。
结构是:
typedef struct{
struct listNode* next;
} listNode;
typedef struct{
listNode* head;
} linkedList;
但是在代码中,当我尝试执行时: node->next = list->head
我收到“来自不兼容指针类型的赋值”错误。任何帮助将不胜感激,因为我真的可以看到任何错误!谢谢
struct listNode您在 upper 中提到了 a typedef,但这没有声明。
你需要按正确的顺序做事:
+----At this point, we can refer to "struct listNode"
v
struct listNode {
struct listNode *next; /* We know this self-references, uses the same name. */
};
/* Now establish a shorthand name for the struct ... */
typedef struct listNode listNode;
/* ... which we can use in subsequent declarations like this. */
typedef struct {
listNode *head;
} linkedList;