Can someone explain the purpose of std::ostream &out
for this friend overloaded operator function? Why not just use std::cout
inside the function?
friend std::ostream& operator<<(std::ostream& out, const Complex& c)
{
out << c.real;
out << "+i" << c.imag << endl;
return out;
}
Instead, like so:
friend operator<<(const Complex& c)
{
std::cout << c.real;
std::cout << "+i" << c.imag << endl;
}