操作符重载的新内容,当我尝试使用<<来重载运算符时,我得到了一个未解决的全局错误消息。错误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;
}