gpt4 book ai didi

c - 结构声明中的 "Parse error"

转载 作者:太空宇宙 更新时间:2023-11-04 00:27:36 25 4
gpt4 key购买 nike

我想在 C 中使用一些基本结构,如下所示:

struct p {
int a;
int b;
p * next;
}

但是,它无法编译并出现 error: parse error before "p" on the line with p * next;

你知道这个问题的原因是什么吗?

最佳答案

C 结构存在于不同的命名空间中并且必须明确限定范围,因此:

struct p {
int a;
int b;
struct p * next;
};

不要忘记末尾的分号! :-)

你可以这样假装你在 C++ 中:typedef struct p {/*...*/} p;。但我认为 next 仍然会像上面那样声明。

关于c - 结构声明中的 "Parse error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2543590/

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