<<操作员超载为朋友

时间:2017-02-19 20:48:55

标签: c++ overloading

操作符重载的新内容,当我尝试使用<<来重载运算符时,我得到了一个未解决的全局错误消息。错误LNK1120和2019.任何人都知道为什么?谢谢!

template <class Type>
class ListType {
 public:
 .. 
 friend std::ostream& operator<< (std::ostream&, const ListType &);    
 };

 template <class Type>
 std::ostream& operator<< (std::ostream& out, const ListType<Type>& list) {
  if (list.head) {
    NodeType<Type> *temp = list.head;
    out << list.head->item;
    temp = temp->next;
    while (temp != 0) {
        out << "," << temp->item;
        temp = temp->next;
    }
  }
return out;
}

0 个答案:

没有答案