Here's my code:
template<typename T>
class list {
private:
node<T>* head;
node<T>* tail;
int len;
public:
list(){
this->len = 0;
this->head = this->tail = 0;
}
~list(){
node<T>* n = this->head;
if (!n) return;
node<T>* t = NULL;
while (n){
t = n->next;
delete n;
n = t;
}
}
/* other stuff */
ostream& operator<<(ostream &o, const list<T>& l) {
node<T>* t = l.head;
while (t){
strm << *(t->value);
if (!t->next) break;
strm << ", ";
t = t->next;
}
return strm;
}
};
I get the following compile error:
rm bin *.o -f
g++ -g -Wall main.cpp -o bin
main.cpp:110: error: 'std::ostream& list<T>::operator<<(std::ostream&, const list<T>&)' must take exactly one argumentmain.cpp: In function 'int main(int, char**)':
main.cpp:151: error: no match for 'operator<<' in 'std::cout << l'
/usr/include/c++/4.4/ostream:108: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
... other errors
make: *** [main] Error 1
So, here's my question. What do I need to do to make this work? I was trying to follow this question as an example.