Why Operator << is defined as a non member function?

Hi,

Can you please explain why we have to declare the operators such as "<<" and ">>" as a non member functions?

Regards,
Rajeev N Sambhu
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.
Hi Peter,

Thank you very much for your reply.

Regards,
Rajeev N Sambhu
Topic archived. No new replies allowed.