【发布时间】:2015-01-06 20:27:29
【问题描述】:
错误:取消引用指向不完整类型的指针
代码块在我创建二叉搜索树时在 main.c 第 10 行 (print_bst(tree->root)) (取消引用指向不完整类型的指针) 中给了我这个错误,但我找不到原因这个错误。
BST.h
typedef struct Node Node;
typedef struct Tree Tree;
Tree *create_bst();
Node *create_node(int data);
void insert_bst(Tree *tree);
void print_bst(Node *root);
BST.c
#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
void *dataPtr;
int data;
struct Node *left;
struct Node *right;
} Node;
typedef struct Tree{
int count;
Node* root;
} Tree;
Tree *create_bst()
{
Tree *tree = (Tree*) calloc(1,sizeof(Tree));
if(tree == NULL){
printf("calloc() failed!\n");
return NULL;
}
tree->count = 0;
tree->root = NULL;
return tree;
}
Node *create_node(int data)
{
Node *node = (Node*) calloc(1, sizeof(Node));
if(node == NULL){
printf("calloc() failed!\n");
return NULL;
}
node->data = data;
node->right = NULL;
node->left = NULL;
return node;
}
main.c
#include <stdio.h>
#include <stdlib.h>
#include "BST.h"
int main()
{
Tree *tree = create_bst();
while(1){
insert_bst(tree);
print_bst(tree->root);
}
return 0;
}
错误信息指的是 main.c 中的第 10 行,(print_bst(tree->root))。
【问题讨论】:
标签: c pointers compiler-errors codeblocks binary-search-tree