Operator overloading >>?

how can we call istream class object in our class “complex” ?

@mehulbhandari358,
Your doubt is not clear, what do you want to do…??

where is operator overloading done in class comlex ? or outside of it.

@mehulbhandari358,
Inside, in fact operator overloading can only be done inside a class.

but in the webinar overloading “<<” cin sir did it outside the function.
ex. cin<<vector ?

1 Like

@mehulbhandari358,
That’s because it is a unary operator, you can overload unary operator outside class also, but if for e.g you have to overload + operator, then you need to have a class.

why was << this overloaded outiside the class

@mehulbhandari358,
Because it is already a member of istream class, and we can not redefine it, thus we declare it outside the class as a friend function. Read more here

can we overload an operator outside a class
and call it for the class object.

@mehulbhandari358,
That’s what bhaiya did in webinar.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.