I've been learning C++.
From this page, I understood that overloading "<<" operator of ostream can be done in this way.
ostream& operator<<(ostream& out, Objects& obj) {
//
return out;
}
//Implementation
and
friend ostream& operator<<(ostream& out, Object& obj);
//In the corresponding header file
My question is... why does this function need "&" at the end of ostream
and Object
?
At least I know that "&" is used to...
- Take the address of a value
- Declare a reference to a type
However, I think neither of them applies to the overloading described above. I've spent a lot of time in googling and reading a text book, but I can't find the answer.
Any advice will be appreciated.