This question already has an answer here:
I've got a class IntegerList, which extends from List. List is a template class which uses a Node<T> class. In list.cpp I overload the operator<< like that:
template <typename T>
ostream& operator<<(ostream& output, const List<T>& lista)
{
Nodo<T>* aux = lista.head;
if (aux == NULL)
output << "Lista vuota.";
else
{
while (aux != NULL)
{
output << aux->getValue() << " ";
aux = aux->getNext();
}
}
return output;
}
and in main I use the operator doing cout << list (list is an istance of IntegerList). Although I have included iostream and the std namespace in all .h/.hpp project's files, when I try to compile the main I've got this linker's error:
Error LNK2019 reference to extern symbol "class std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > &,class List const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$List@H@@@Z) not solved in function _main
I don't think that it's a template problem: I was able to define my template functions in the .cpp doing something like this: http://ift.tt/1WGzQOa
Aucun commentaire:
Enregistrer un commentaire