Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RecursiveFree函数-警告:从不兼容的指针类型初始化[-Wincompatible指针类型]_C_Pointers_Recursion_Nodes_Quadtree - Fatal编程技术网

RecursiveFree函数-警告:从不兼容的指针类型初始化[-Wincompatible指针类型]

RecursiveFree函数-警告:从不兼容的指针类型初始化[-Wincompatible指针类型],c,pointers,recursion,nodes,quadtree,C,Pointers,Recursion,Nodes,Quadtree,我有一个递归释放的函数: #include "treeStructure.h" void destroyTree (Node* p) { if (p==NULL) return; Node* free_next = p -> child; //getting the address of the following item before p is freed free (p); //freeing p destroyTree(free_n

我有一个递归释放的函数:

#include "treeStructure.h"

void destroyTree (Node* p)
{
    if (p==NULL)
        return;
    Node* free_next = p -> child; //getting the address of the following item before p is freed
    free (p); //freeing p
    destroyTree(free_next); //calling clone of the function to recursively free the next item
}
treeststructure.h:

struct qnode {
  int level;
  double xy[2];
  struct qnode *child[4];
};
typedef struct qnode Node;
我一直在犯错误

警告:从不兼容的指针类型初始化[-Wincompatible指针类型]

它指向“p”

我不明白为什么会这样


有人能解释一下并告诉我如何解决这个问题吗?

您会收到错误消息,因为指向
节点的数组(
子节点
)的指针不能转换为指向
节点
p
)的指针

由于
child
是指向
Node
的四个指针的数组,因此必须分别释放它们:

void destroyTree (Node* p)
{
    if (!p) return;

    for (size_t i = 0; i < 4; ++i)
        destroyTree(p->child[i]);

    free(p);
}
void销毁树(节点*p)
{
如果(!p)返回;
对于(尺寸i=0;i<4;++i)
破坏树(p->child[i]);
自由基(p);
}

@usr我链接了一个具有节点结构的头文件。我在上面添加了它以显示它是如何链接的。Child是指向节点的指针数组,而不是指向节点的单个指针。@swardfish参数应该是Node**p,不是吗?子字段的类型为Node**@anon2000
child[i]
的类型为
Node*