Why ostream operators not overloaded using member functions?
Consider the following line:
cout<<obj;
where obj is the object of Demo class.
In this case we are overloading "<<" operator. But
overloading the binary
operator using member function, the left hand operand should be
the object of relevant class.
Here in this case left hand side operand is not the object of
Demo class. It is object of ostream class.
Hence we cant overload ostream operators using member function.
But we can overload these type of operators using friend
functions.
Thanks,
Prof. D. H. Ingole