Operator overloading help!!

I understand the concept of operator overloading but i dont understand what is going on if that makes sense. In this piece of code, why has cout been replaced with os and i dont understand what the first parameter means (ostream& os)
Please help me

ostream& operator<<(ostream& os, const Critter& a_Critter)
{
os<<"Critter Object - ";
os<<"m_Name: "<<a_Critter.m_Name;
return os;
}
cout is just one possible output stream, another common one is output to a disk file. The << operator will work with any of these ostreams.

In the code above the first parameter will be replaced by whichever stream the function is called on, which may commonly be cout, but doesn't have to be.

The reason why the return value is also an ostream (the same ostream in fact) is so that you can use this << operator as part of a longer line, where other variables will also be sent to the output stream.
Topic archived. No new replies allowed.