時候我已經檢查然而這篇文章C++ function template partial specialization?C++函數模板部分特例錯誤重載運營商
,以下錯誤仍撲朔迷離。爲什麼template-id與函數聲明不匹配?
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);
我實現紅黑樹類RBTree任何輸入型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;
}
C++不允許你以部分專門的函數,該函數名前應刪除。 –
sangrey
[重載模板類的朋友操作符<<]可能重複(http://stackoverflow.com/questions/4660123/overloading-friend-operator-for-template-class) –
@sangrey事實上C++不允許專門化成員函數。 – lsbbo