“必须使用'struct'标记来引用类型'node'”。 [英] "Must use 'struct' tag to refer to type 'node'"
问题描述
这是怎么回事?我正在
必须使用'struct'标记来引用类型'node'
Must use 'struct' tag to refer to type 'node'
在
typedef struct node {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
} node;
我也尝试过
typedef struct node {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
};
和
struct node {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
};
和
typedef struct {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
} node;
和
typedef struct treeNode {
char * fx; // function
treeNode * gx; // left-hand side
char * op; // operator
treeNode * hx; // right-hand side
} node;
我都为这些错误。再次在普通C语言中正确的语法是什么?
and I get errors for all of those. What is the proper syntax in plain C again?
推荐答案
让我们看一下第一个代码段:
Let's look at the first snippet:
typedef struct node {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
} node;
gx
和 hx
出现在结构节点
/ 节点
类型定义的中间,在 typedef
语句已完成。在程序中,此时 node
不是有效的类型名称,因为 typedef
尚未结束(并且与C ++不同,编写 struct节点{...};
不会自动将 node
设为类型名称)。但是,此时 struct节点
是有效的类型名称(只要您仅将其用于指针类型),因此为了声明 gx
和 hx
正确,您需要编写:
gx
and hx
occur in the middle of the struct node
/node
type definition, before the typedef
statement is complete. At this point in the program, node
is not a valid type name, because the typedef
isn't over yet (and, unlike C++, writing struct node { ... };
does not automatically make node
a type name). However, struct node
is a valid type name at this point (as long as you only use it for pointer types), so in order to declare gx
and hx
properly, you need to write:
typedef struct node {
char * fx; // function
struct node * gx; // left-hand side
char * op; // operator
struct node * hx; // right-hand side
} node;
这篇关于“必须使用'struct'标记来引用类型'node'”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!