I have a class, defined in a head as:
template <typename T> class MyClass
{
template <typename U> friend std::ostream& operator<<(std::ostream& output, const MyClass<U>& p);
public:
...
}
In an implementation file, I have:
template <typename U> std::ostream& operator<<(std::ostream& output, const MyClass<U>& m)
{
output << "Some stuff";
return output;
}
Which all looks fairly kosher. However, when I try and use this operator (i.e. std::cout << MyClass()), I get the following linker error:
Undefined symbols: std::basic_ostream<char, std::char_traits<char> >& operator<< <InnerType>(std::basic_ostream<char, std::char_traits<char> >&, MyClass<InnerType> const&)
I am suprised the compiler hasn't automagicially generated this for me... Any suggestions as to what I'm doing wrong?