【发布时间】:2023-03-16 08:15:02
【问题描述】:
当我尝试malloc() struct bstree 节点时,我的编译器报告错误:
从“void*”到“bstree*”的无效转换
这是我的代码:
struct bstree {
int key;
char *value;
struct bstree *left;
struct bstree *right;
};
struct bstree *bstree_create(int key, char *value) {
struct bstree *node;
node = malloc(sizeof (*node));
if (node != NULL) {
node->key = key;
node->value = value;
node->left = NULL;
node->right = NULL;
}
return node;
}
【问题讨论】:
-
您是否尝试使用 C++ 编译器编译 C 代码?
标签: c++ c pointers dynamic-memory-allocation