I have a class defined in my head as:
template <typename T> class MyClass
{
template <typename U> friend std::ostream& operator<<(std::ostream& output, const MyClass<U>& p);
public:
...
}
In the implementation file, I:
template <typename U> std::ostream& operator<<(std::ostream& output, const MyClass<U>& m)
{
output << "Some stuff";
return output;
}
That everything looks pretty kosher. However, when I try to 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 surprised that the compiler did not automatically create this for me ... Any suggestions as to what I am doing wrong?
source
share