这里发生了什么?我越来越
必须使用'struct'标签来引用'node'类型
在gx与hx线
typedef struct node {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
} node;
Run Code Online (Sandbox Code Playgroud)
我也试过了
typedef struct node {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
};
Run Code Online (Sandbox Code Playgroud)
和
struct node {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
};
Run Code Online (Sandbox Code Playgroud)
和
typedef struct {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
} node;
Run Code Online (Sandbox Code Playgroud)
和
typedef struct treeNode {
char * fx; // function
treeNode * gx; // left-hand side
char * op; // operator
treeNode * hx; // right-hand side
} node;
Run Code Online (Sandbox Code Playgroud)
我得到了所有这些错误.普通C中的正确语法是什么?
Iha*_*imi 10
在c中,您不能使用结构名称来引用struct,您需要struct在名称之前添加,或者您可以使用typedef它
typedef struct node node;
struct node
{
/* Whatever */
node *link;
};
Run Code Online (Sandbox Code Playgroud)
让我们看一下第一个片段:
typedef struct node {
char * fx; // function
node * gx; // left-hand side
char * op; // operator
node * hx; // right-hand side
} node;
Run Code Online (Sandbox Code Playgroud)
gx并hx在语句完成之前出现在struct node/ node类型定义的中间typedef。在程序中,node这不是有效的类型名称,因为typedef还没有结束(并且与C ++不同,编写struct node { ... };不会自动node生成类型名称)。然而,struct node 就是在这一点上有效的类型名称(只要你只使用它的指针类型),所以为了申报gx和hx正确,你需要写:
typedef struct node {
char * fx; // function
struct node * gx; // left-hand side
char * op; // operator
struct node * hx; // right-hand side
} node;
Run Code Online (Sandbox Code Playgroud)