i'm trying to implement tree structure in c:
this part is from the header file:
typedef struct SP_Tree_Node
{
char * value;
struct Node * children;
int indexOfLastChild;
} Node;
typedef struct SP_Tree
{
Node root;
} Tree;
when i'm trying to insert new Node into children array the next error appears: "dereferencing pointer to incomplete type" this is the code: (tree's type is Tree *)
Node * newNode = (Node*) malloc(sizeof(Node*));
tree->root.children[tree->root.indexOfLastChild] = newNode;
what am i doing wrong? thank you!!
struct Node
is different from Node
, and it doesn't seem you defined `struct Node.
Try changing struct Node * children;
in the declaration of struct SP_Tree_Node
to struct SP_Tree_Node * children;
UPDATE:
You use array of Node*
, so the declaration should be struct SP_Tree_Node ** children;
(add one more asterisk).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.