C 错误 - 函数不能超载

c++ error - function cannot be overloaded

本文关键字:不能 超载 函数 错误      更新时间:2023-10-16

以下是用于复制二进制树的C 代码。我正在尝试超载复制功能。我认为这应该起作用,因为这两个功能的返回类型不同。

node* copy(node *onode,node *cnode)
{
    if(root==NULL)
        root=onode;
    if(onode)
    {
        cnode=new node;
        cnode->data=onode->data;
        cnode->left=copy(onode->left,cnode->left);
        cnode->right=copy(onode->right,cnode->right);
        return cnode;
    }
        return cnode;
}
void copy(node *onode,node* cnode)
{
    onode=copy(onode,cnode);
}

但是,我在编译时会出现以下错误。

错误:‘void tree :: copy(node*,node*('不能超载 void copy(节点 onode,node cnode( 错误:带有'node*tree :: copy(node*,node*(' 节点 *复制(节点 *onode,node *cnode(

谢谢。

返回类型只有在参数根据过载规则

不同时才能有所不同。