gpt4 book ai didi

c++ - 结构的排序

转载 作者:太空宇宙 更新时间:2023-11-03 10:45:51 24 4
gpt4 key购买 nike

当我尝试执行此操作时遇到编译错误

 struct Child{
char Name[8];
Parent *P;
};

struct Parent{
char Name[8];
Child *C;
};

编译器提示它无法在 struct Child 中找到 Parent,但交换它们的顺序没有帮助。编译器会提示它无法在 Parent 中找到 Child。我如何解决这个错误,为什么我在编写程序时没有突出显示错误。

最佳答案

您可以添加 forward declaration :

struct Parent;   //forward declaration
struct Child{
char Name[8];
Parent *P;
};

关于c++ - 结构的排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22063079/

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