I'm trying to overload the ostream operator to allow output for a nested class inside a template. However, the compiler is unable to bind the actual function call to my overload.
template <class T>
struct foo
{
struct bar { };
};
template <class T>
std::ostream& operator << (std::ostream& os,
const typename foo<T>::bar& b)
{
return os;
}
int main()
{
foo<int>::bar b;
std::cout << b << std::endl; // fails to compile
}
This will compile if I define the overload as an inline friend
function:
template <class T>
struct foo
{
struct bar
{
friend std::ostream& operator << (std::ostream& os, const bar& b)
{
return os;
}
};
};
But I'd rather define the overload outside of the class. Is this possible?