I have checked this post C++ function template partial specialization?
However, the following error is still confusing. Why does template-id not match the function declaration?
error: function template partial specialization ‘operator<< <T>’ is not allowed
ostream& operator<< <T>( ostream& out, RBTree<T>& rbt)
error: template-id ‘operator<< <int>’ for ‘std::ostream& operator<<(std::ostream&, RBTree<int>&)’ does not match any template declaration
friend ostream& operator<< <T>( ostream& out, RBTree<T>& rbt);
I am implementing the red-black tree with class RBTree for any input type T.
class RBTree{
friend ostream& operator<< <T>( ostream& out, RBTree<T>& rbt);
public:
RBTree(){ nil = new RBTreeNode<T>( BLACK ); root = nil; }
.....
};
template<class T>
ostream& operator<< <T>( ostream& out, RBTree<T>& rbt)
{
rbt.InOrder( rbt.GetRoot(), out );
return out;
}