gpt4 book ai didi

c - 在结构错误中指向取消引用

转载 作者:太空狗 更新时间:2023-10-29 15:20:08 26 4
gpt4 key购买 nike

我有一个创建循环列表的函数,我在编译时遇到问题,不确定它是否是语法,如果有人能提供帮助,我将不胜感激。

    void CreateCircularList(struct node** listRef, struct node** tailRef)

{
Push(&*listRef, "String 1");
*tailRef=*listRef;
Push(&*listRef, "String 2");
Push(&*listRef, "String 3");
Push(&*listRef, "String 4");

*(tailRef->next)=*listRef;

}

编译器在最后一行标记错误:

"Member reference base type 'struct node*' is not a structure or union"

有什么想法吗?谢谢

最佳答案

你可能想要

  (*tailRef)->next = *listRef;

作为最后一个作业。

你不能写 tailRef->next 因为 tailRef 是指向指针的指针。

出于可读性原因,我还建议只编写 Push(listRef, "Some string"); 而不是你的 Push(&*listRef, "Some string"); .

关于c - 在结构错误中指向取消引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14766683/

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