When you are going to print an object, a friend operator<< is used. Can we use member function for operator<< ?
class A {
public:
void operator<
You can't. But If you don't want it to be a friend function, make it a free function and implement it in terms of the class' public interface. For eg.
ostream& operator<<(ostream& os, Myclass& obj)
{
return obj.print(os);
}
ostream& MyClass::print(ostream& os)
{
os << val; // for example.
return os;
}