Hey Everyone,
So, I'm having an issue with a compiler error (C3861 to be exact). I'm creating a Binary Search Tree for my C++ course. The Binary Search Tree needs to overload the << operator & print the data in the tree inorder. My initial thought on solving this problem was to simply overload << as usual, & call a private method which would return the output to <<. However, this has lead to my compiler error. Any help would be appreciated!
My .h file:
class BSTree {
friend ostream& operator<<(ostream&, const BSTree&);
public:
BSTree();
BSTree(const BSTree &);
~BSTree();
...
private:
ostream& outputHelper(ostream&, Node *);
...
My .cpp file:
ostream& BSTree::outputHelper(ostream &output, Node *root) {
if(root != NULL) {
outputHelper(output, root->left);
output << root->data;
outputHelper(output, root->right);
}
return output;
}
ostream& operator<<(ostream &output, const BSTree &other) {
output << outputHelper(&output, other.overallRoot);
return output;
}