为什么我的结构没有定义?C语言中的队列
我需要一个非常简单的队列进行FIFO操作: 我已经使用过结构,所以我使用了一些为达到目的而修改的旧代码:但现在我的编译器不接受节点作为结构,并且我遇到了一些不兼容的指针问题。希望有人看到我遗漏的东西: 代码: 错误:为什么我的结构没有定义?C语言中的队列,c,struct,queue,C,Struct,Queue,我需要一个非常简单的队列进行FIFO操作: 我已经使用过结构,所以我使用了一些为达到目的而修改的旧代码:但现在我的编译器不接受节点作为结构,并且我遇到了一些不兼容的指针问题。希望有人看到我遗漏的东西: 代码: 错误: .6:2: error: unknown type name ‘Node’ Node* next; ^ In function ‘enqueue’: :23:15: warning: initialization from incompatible pointer typ
.6:2: error: unknown type name ‘Node’
Node* next;
^
In function ‘enqueue’:
:23:15: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
Node* next = root->next;
^
c:27:9: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
next = root->next;
^
c:29:14: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
root->next = newTask;
^
c: In function ‘dequeue’:
c:38:11: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
q->head = root->next;
Thx提前
Tim4497当您声明字段
节点*next时代码>,编译器不知道名为节点的类型。它只知道struct Node
@Eugene他键入了strutct,所以它应该只知道Node。@Fredrik这是在字段声明之后发生的。是的,刚刚解决了所有问题。。。谢谢:)但我很好奇,因为我在没有结构的情况下使用了它,它工作了?@Tim4497也许你有typedef结构节点代码>在此之前。或者使用C++编译器,(不确定)允许这样做。
.6:2: error: unknown type name ‘Node’
Node* next;
^
In function ‘enqueue’:
:23:15: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
Node* next = root->next;
^
c:27:9: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
next = root->next;
^
c:29:14: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
root->next = newTask;
^
c: In function ‘dequeue’:
c:38:11: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
q->head = root->next;