I get some compiling errors about template instantiation :wall: , but I can't find where the syntax errors happens. Can some help me?
template<typename Type> class SingleList;
template<typename Type> class SingleListNode{
private:
friend class SingleList<Type>;
SingleListNode() : next(NULL){}
public:
friend ostream& operator<< <Type>(ostream& os,SingleListNode<Type>& sln); //Error!!!
private:
SingleListNode *next;
};
template<typename Type> ostream& operator<<(ostream& os,SingleListNode<Type>& out){
os<<out.data;
return os;
}
template<typename Type> class SingleList{
public:
SingleList()
{
head = new SingleListNode<Type> () ; //Error!!!
}
~SingleList(){
delete head;
}
private:
SingleListNode<Type> *head;
};
Compiler error message:
|| g++ -g -I ./inc/ -c single_list_test.cpp -o single_list_test.o
|| single_list.h: In instantiation of �SingleListNode<int>�:
single_list.h|25 col 13| instantiated from �SingleList<Type>::SingleList() [with Type = int]�
single_list_test.cpp|9 col 18| instantiated from here
single_list.h|10 col 18| error: template-id �operator<< <int>� for �std::ostream& operator<<(std::ostream&, SingleListNode<int>&)� does not match any template declaration
|| make:
*** [single_list_test.o] Error 1