Following is a c++ code for copying a binary tree. I am trying to overload copy function. I think it should work because return type of these two functions is different.
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);
}
However, I get following error at compilation.
error: ‘void tree::copy(node*, node*)’ cannot be overloaded void copy(node onode,node cnode) error: with ‘node* tree::copy(node*, node*)’ node* copy(node *onode,node *cnode)
Thanks.