What does it mean to pass a &variable to a function? E.g., string& insert ( size_t pos1, const strin
- by Bob Montgomery
I understand passing a pointer, and returning a pointer:
char * strcat ( char * destination, const char * source );
You're passing a variable that contains the address to a char; returning the same.
But what does it mean to pass something using the reference operator? Or to return it?
string& insert ( size_t pos1, const string& str );
I mean, I understand what actually happens, I just don't understand the notation. Why isn't the notation this instead:
string * insert ( size_t pos1, const string * str ); //made up
I presume it has something to do with passing/returning the instance of a class, but what? Is this syntax valid; if not why not and if so what does it mean?
char & strcat ( char & destination, const char & source ); //made up
(all of the function declarations, except the last made-up two, are from http://www.cplusplus.com )