Classes and function


Why here we use & in return type what its meaning

Hey Mayur, one thing is your are trying to overload << operator for istream, you can’t do that because we use >> operator for istream and << operator for ostream.
And the code snippet’s screenshot you have shared isn’t having & in its return type, if you want to return it by reference then it should be like this istream& operator>>(istream &is, Complex &c). Now when we are overloading << operator then we should return it by reference because using an istream return type would require calling the istream copy constructor, and as the istream class does not have a public copy constructor. So, returning a reference to cin poses no problems because cin is already in scope of the calling function. Otherwise if you don’t return by reference your operator may not be overloaded and if you use the void return type you will not be able to chain the stream operations.