overloading ostream template trouble

I am currently learning about data structures. I haven't had much trouble up until now and I have looked all over the Internet to find why my code is not working but haven't found an answer. The compiler tells me I have an "Undefined reference to 'operator<<(ostream& osObject, listType<int>& const)'" if I take function call out of main everything compiles fine.

declaration:
friend std::ostream& operator<<(std::ostream&, const listType<Type>&);

definition:
template<class Type>
std::ostream& operator<<(std::ostream& osObject,
const listType<Type>& list)
{
listType<Type>* current; //pointer to traverse list
current = list.first; //set pointer to first node
while(current != NULL) //iterate through the list
{
osObject << current->info << " "; //send info to screen
current = current->link; //on to the next one
}

return osObject;
}

main():
listType<int> intList;
...
...
cout << intList;

I have them stored in one .cpp file because I was told you can't have a template in a .h file.

Any help someone could offer would be appreciated.
Topic archived. No new replies allowed.