In the class definition in the header:
struct Foo
{
int a, b;
friend std::ostream& operator<<(std::ostream &os, const Foo&);
};
In an implementation (e.g. .cpp
file):
std::ostream& operator<<(std::ostream &os, const Foo& f)
{
return os << f.a << " " << f.b;
}