While going over some code I came across the following line of code
ostream& out = resp.send();
The way I interpreted it was that the resp object has a send method that returns an ostream object called out. What is the purpose of the ‘&’ symbol here? Does it mean that the resp object returns a reference to an object of type ostream?
It will be great to get some clarification.
Thanks
You are right. The & creates a reference named ‘out’ to the ostream object that was returned by reference from resp.send().
Note: We know that it was returned by reference because standard stream objects can not be copied therefore it can not be returned by value.
For example:
Here is a nice explanation of references in C++ (from Bruce Eckel’s book Thinking in C++)