operator<< and operator>> operates on two objects. If you define it as a member function of class Foo it means that the first operand has to be of type Foo. By defining it as a non-member function we can choose whatever type we want as the first operand.