C++ 无法将BTreeNode*强制转换为BTreeP&;(typedef BTreeNode*BTreeP;)

C++ 无法将BTreeNode*强制转换为BTreeP&;(typedef BTreeNode*BTreeP;),c++,pointers,types,reference,C++,Pointers,Types,Reference,我写了一个关于BTree的程序,代码如下: class BTreeNode { public: ... BTreeNode* getChild(const int i); private: ... }; typedef BTreeNode* BTreeP; void _insert_key_to_unfull_tree(BTreeP &tree, int key); // the problematic implementaion _insert_key_to_un

我写了一个关于BTree的程序,代码如下:

class BTreeNode 
{
public:
...
    BTreeNode* getChild(const int i);    
private:
...
};
typedef BTreeNode* BTreeP;

void _insert_key_to_unfull_tree(BTreeP &tree, int key);

// the problematic implementaion
_insert_key_to_unfull_tree(tree->getChild(i), key);

编译器说不能将BTreeNode*强制转换为BTreeP&,我应该如何修复此问题?

\u将密钥插入到unfull\u树(*(tree->getChild(I)),密钥)


当然,您可能需要验证getChild不返回null

函数
\u insert\u key\u to\u unfull\u tree
需要指向指针的引用:

void _insert_key_to_unfull_tree(BTreeNode*& tree, int key);
BTreeNode*& getChild(const int i);    
尝试更改
getChild
,使其返回对指针的引用:

void _insert_key_to_unfull_tree(BTreeNode*& tree, int key);
BTreeNode*& getChild(const int i);    

顺便说一句,您可能需要删除
typedef BTreeNode*BTreeP
,以减少混淆。

我知道这个typedef会引起混淆,但a有大量基于它的代码。而且,BTreeNode*可以强制转换为常量BTreeP&,而BTreeP可以强制转换为BTreeP&,我不理解其中的区别……我有一个函数_alloc_tree(BTreeP&tree),它与一个BTreeP类型参数一起工作,该参数将是“不能将BTreeNode转换为BTreeP&”,我还有一个函数_alloc_tree(BTreeP&tree),它与一个BTreeP类型参数一起工作