Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的结构没有定义?C语言中的队列_C_Struct_Queue - Fatal编程技术网

为什么我的结构没有定义?C语言中的队列

为什么我的结构没有定义?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

我需要一个非常简单的队列进行FIFO操作: 我已经使用过结构,所以我使用了一些为达到目的而修改的旧代码:但现在我的编译器不接受节点作为结构,并且我遇到了一些不兼容的指针问题。希望有人看到我遗漏的东西:

代码:

错误:

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