Trying to overload << in a templated Binary Tree
So that if I have a binary tree:
Code:
BinaryTree<int> *t = new BinaryTree<int>(5);
And there have been more numbers inserted I can just say:
I have overloaded this operator before, but never with templates, so I am unsure where I should start.
Here is my BinaryTree class:
Code:
template <class T>
class BinaryTree{
public:
BinaryTree(T); //constructor
BinaryTree<T>* insert(T, BinaryTree<T>*);
void inorder(BinaryTree<T>*); //prints using inorder traversal
int countNodes(BinaryTree<T>*);
private:
T data;
BinaryTree* left;
BinaryTree* right;
};
I believe the function should be something like this:
Code:
friend ostream& operator<< <>(ostream&, const BinaryTree<T>&)
I know you can't put << or >> overloaded functions as a member function, so does this not require a prototype, or just put it outside of the class and above the implementation?
Hope this makes sense, thanks.
*EDIT* Actually, I am supposed to make it a friend function, so I would put it in the class