當我嘗試malloc()
一個struct bstree
節點,我的編譯器報告錯誤:C++的malloc無效轉換到結構
invalid conversion from 'void*' to '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代碼嗎? – SergeyA