gpt4 book ai didi

c - 字段类型不完整?

转载 作者:太空宇宙 更新时间:2023-11-04 06:31:08 24 4
gpt4 key购买 nike

我收到有关结构元素的错误。

struct trie {
char ch;
bool isEnd;
struct trie arr[4];
struct trie *next;
};

错误:

error: field ‘arr’ has incomplete type

最佳答案

你可以这样定义你的结构

struct trie {
char ch;
bool isEnd;
struct trie *arr[4];
struct trie *next;
};

请注意(为了避免无限递归)arr 现在是一个包含四个指针 的数组,每个指针都指向一个您必须动态分配的trie 结构在你的代码上。

你可以用这个函数分配一个trie(当然是未初始化的):

struct trie *alloc_trie() {
return malloc(sizeof(struct trie));
}

注意arr的四项指向的四个trie没有分配。 下一个也不是。

关于c - 字段类型不完整?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20439695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com