We all know how to implement operator overloading as the following:
But sometimes I see people use friend methods:Code:class complex { public: complex(double r, double i){ real = r, imag = i;} complex operator +(const complex & c); };
Code:class complex { public: complex(double r, double i){ real = r, imag = i;} friend complex operator +(const complex &c1, const complex &c2); };
Why do they do this way? What're the advantages?
Thank you.