#include <stdio.h>
#include <stdlib.h>
struct tree {
int data;
struct tree *left, *right;
};
struct queue {
struct tree **nodeQ = (struct tree**)malloc(sizeof(struct tree*));
int front;
int rear;
};
最佳答案
在 C 中,您无法像尝试使用 nodeQ
成员那样内联初始化结构成员。
创建结构体时需要初始化成员。
所以你需要做类似的事情
struct queue q = { malloc(sizeof(struct tree *)), 0, 0 };
或
struct queue *q = malloc(sizeof(struct queue));
q->nodeQ = malloc(sizeof(struct tree *));
q->front = 0;
q->rear = 0;
请注意,我 do not cast the result of malloc
.
关于c - 如何删除 ':' token 之前的错误 : expected ',' , ';' 、 '}' 、 '__attribute__' 或 '=' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35964013/