I first made a complex class in C ++ that had two data members - real and imaginary. (forms a + ib). when I tried to overload the <<operator for a complex class object as follows:
friend ostream operator<<(ostream ,complex ); in .h file
ostream operator <<(ostream o,complex c){
o<<"real part"<<c.real;
o<<"imaginary part<<c.imaginary;
return o;
}
in the .cpp file, it does not work and rather opens the ios_base file and shows an error there. but the same code overloads <<excellent when I follow the link and return the link as follows -
ostream& operator <<(ostream& o,complex& c)
{
};
I don’t understand how the transfer and return by link helps?
source
share