#include <iostream>
using namespace std;
class foo
{
int a;
public:
friend ostream& operator << ( ostream & os, foo const & f )
{
os << f.a << std::endl;
return os;
}
};
int main()
{
foo f;
cout << f << endl;
return 0;
}
That should work ^^ (it does for me).
What I said before about needed the friend because the operator wasnt a member function was wrong, its just the way I learnt it. There are some problems with the stream's not working with class operators only with global ones (because of the ordering of variables I think), maybe some one else with help clarify the stituation.