小编use*_*329的帖子

C++ malloc无效从`void*'转换为struct

当我尝试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;
}
Run Code Online (Sandbox Code Playgroud)

c c++ pointers dynamic-memory-allocation

3
推荐指数
1
解决办法
5524
查看次数

标签 统计

c ×1

c++ ×1

dynamic-memory-allocation ×1

pointers ×1