void StringTree::displayTreePrivate(node*Ptr){
if(root!=nullptr){
if(Ptr->left!=nullptr){
displayTreePrivate(Ptr->left);
}
std::cout<< Ptr->key<<" ";
if(Ptr->right!=nullptr){
displayTreePrivate(Ptr->right);
}
else{
std::cout<<"The tree is empty... hmm..";
}
}
}
////////////////////////////////////////////////////////////////////////////
The error is as follows:
C:\Users\Tim Allen\Desktop\C++162\BST\main.cpp|27|error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'void')|
Its an annoyingly small bug. I am pretty sure my logic is right for the code though. This is supposed to be a ordered binary search tree of strings.
Feel free to tear apart my code what could I do better what is ok anything you think will help. Thank you
I do not necessarily understand why that changed or fixed things.
You've defined StringTree::displayTreePrivate as void, so that it doesn't return a value. So you're streaming an undefined value to standard out.
In any case, that method already calls another method which contains the code that outputs data to standard out, so why are you trying to also stream a (non-existant) return value in main?
Also, please use code tags when posting code, to make it readable:
However I do not necessarily understand why that changed or fixed things.
Well the cout was not needed in the first place. Function displayTree() which invokes displayTreePrivate() has its own cout inside the function.
It also wouldn't make sense to try to do anything with the value returned by a function when the function is declared as void and thus has no return value.