Overloading << operator

In my ListType.h file have

...
public:
...
template<class U>
friend std::ostream& operator<< (std::ostream&, const ListType<U>&);
...

template<class U>
std::ostream& operator<< (std::ostream& out , const ListType<U>& source)
{
if(!source.empty())
{
out << source.list[0];
for (size t i =1; i<source.count; ++i)
{
out << ", " << source.list[i];
}
}
return out;
}

and in my Program05 file i try to use
UListType<int> ulist;
cout << ulist;

and my borland compiler gives me the error:

c:\programs\Program05>bcc32 Program05
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Program05.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external 'std::basic_ostream<char, std::char_traits<char> >& operator <<(std::basic_ostream<char, std::char_traits<ch
ar> >&, const ListType<int>&)' referenced from C:\PROGRAMS\PROGRAM05\PROGRAM05.OBJ

What can i do to resolve this?

size t. You meant size_t.. Or was that a typo (only present here)?
It is a typo only present here.
The problem doesn't seem to be in the code you posted. I expanded it to a compilable minimum, and it compiled fine.
By the way, what is UListType ?
Last edited on
UListType is a derived class from ListType. The UListType.h has the #include "ListType.h" within it. I'm wondering if the problem is with my compiler. Did you use borland or a GNU based compiler?
I used whatever comes with VC++ (some M$ compiler).
Do try different compiler. I believe Borland is somewhat looked down on (though I might be wrong).
Also, try writing a small complete program that reproduces the error. As I've said, the problem probably comes from somewhere else.
Topic archived. No new replies allowed.