Hi guys,
I'm trying to making an instance of a templated operator<< for a
templated class a friend of that class (see below), to allow it to
access the class internals for output purposes.
#include <iostream>
template <typename T>
class TC
{
friend std::ostream& operator<<(std::ostream& os, const TC&);
};
template <typename Tstd::ostream& operator<<(std::ostream& os, const
TC<T>&)
{
return os;
}
int main()
{
TC<inttc;
std::cout << tc;
return 0;
}
Unfortunately the way I've done it is wrong: I'm referring in the above
to a non-template instance instead of a template one (the online Comeau
compiler kindly warned me about this and recommended I add <>...). This
would be ok normally, but because it's an operator I'm having trouble.
VC++ 2005 refuses (probably correctly?) to accept the following:
friend std::ostream& operator<< <>(std::ostream& os, const TC&);
Please can you tell me if I'm missing something? Is this possible for
operators (have I just messed up the syntax)?
Thanks!
Stu