I'm creating a binary tree and I'm trying to implement a function for creating that tree. So that is the code for every member of the tree
template <typename T>
struct Node
{
T data;
Node* left;
Node* right;
Node()
{
data = NULL;
left = NULL;
right = NULL;
}
};
The "BinaryTree" class have only one member called "root" whose type is Node and my function for creating the tree is:
void CreateTree(istream &in)
{
char help;
int data;
in >> help;
while (help == 'y')
{
in >> data;
addLeaf(root, data);
in >> help;
}
}
and the addLeaf function is:
void addLeaf(Node<T>* &nod, int data)
{
if (nod == NULL)
{
nod = new Node<T>();
nod->data = data;
}
else if (data < nod.data) addLeaf(nod->left, data);
else addLeaf(nod->right, data);
}
The result is:
error C2664: 'void BinaryTree::addLeaf(Node *&,int)' : cannot convert argument 1 from 'Node' to 'Node *&'
What should I do?