c1+c2; means c1. +(c2);
void operator +(complex&x)
similarly
complex d;
cin>>d; means what in
void opeartor >>(istream &is,complex &c)
Doubt in operator overloading
Hi Gaurav, please share the corresponding code.
Hey Gaurav,
complex d;
cin>>d;
void opeartor >>(istream &is, complex &co)
in this d is an object of class complex which is passed by reference to the function as function argument co.
so is function is called without any object ?
like: >>(is,co)
No, you can’t call it like this. See here you are overloading the operator >> for input stream so you have to call it as cin>>d; where cin is the istream class’s object and d is the complex class’s object.
c1+ c2 here + is overloaded inside the class
so we are calling the function for c1 object with c2 as parameter such that addition of two object will be added to c1 only while c2 remain unchange.
my doubt is
cin>>d >> is overloaded outside the class
is this function is called for any object or not?
if no than how it is interpreted?
Hey this is called for istream class’s object cin.
any intrepretation for the same