I have been trying to get my class template to print out a string for me. However I am getting a error C679: No operator found which takes a right hand operand of type std:: string
. I have tried various way to make this error disappear.
#include <iostream>
#include <string.h>
using namespace std;
template<class T>
class BinaryTree
{
struct Node
{
T data;
Node* lChildptr;
Node* rChildptr;
Node(T dataNew)
{
data = dataNew;
lChildptr = NULL;
rChildptr = NULL;
}
};
private:
Node* root;
void Insert(Node* &newData, Node* &theRoot)
{
if(theRoot == NULL)
{
theRoot = new Node(newData);
return;
}
else if(newData->data < theRoot->data)
Insert(newData, theRoot->lChildptr);
else
Insert(newData, theRoot->rChildptr);;
}
void insertnode(T item)
{
Node *newData;
newData= new Node;
newData->value = item;
newData->lChildptr = newData = rChildptr = NULL;
insert ( newData, root);
}
void PrintTree(Node* theRoot)
{
if(theRoot)
{
cout << theRoot->data << endl;
PrintTree(theRoot->lChildptr); //<< The error is here
PrintTree(theRoot->rChildptr);
}
}
public:
BinaryTree()
{
root = NULL;
}
void AddItem(T )
{
//Insert(newData, root);
}
void PrintTree()
{
PrintTree(root);
}
};
int main()
{
BinaryTree<string> *tree = new BinaryTree<string>();
tree->AddItem("Erick");
tree->PrintTree();
system ( "pause");
}
I changed
void insertnode(T item)
andvoid Insert(Node* &newData, Node* &theRoot)
and uncommented//Insert(newData, root);
here is fixed code...