取消引用指向不完整类型的指针

时间:2015-12-06 14:49:39

标签: c

我正在尝试在c:

中实现树结构

这部分来自头文件:

typedef struct SP_Tree_Node
{
    char * value;
    struct Node * children;
    int indexOfLastChild;
} Node;

typedef struct SP_Tree
{
    Node root;
} Tree;

当我试图将新节点插入子数组时,出现下一个错误:“取消引用指向不完整类型的指针” 这是代码:(树的类型是Tree *)

Node * newNode = (Node*) malloc(sizeof(Node*));
tree->root.children[tree->root.indexOfLastChild] = newNode;
我在做错了什么? 谢谢!!

1 个答案:

答案 0 :(得分:3)

struct NodeNode不同,并且它似乎没有定义`struct Node。

尝试将struct Node * children;声明中的struct SP_Tree_Node更改为struct SP_Tree_Node * children;

<强>更新

您使用Node*数组,因此声明应为struct SP_Tree_Node ** children;(再添加一个星号)。