I\'m currently reading through Accelerated C++ and I realized I don\'t really understand how & works in function signatures.
int* ptr=#
The &
character in C++ is dual purpose. It can mean (at least)
The use you're referring to in the function signature is an instance of #2. The parameter string& str
is a reference to a string
instance. This is not just limited to function signatures, it can occur in method bodies as well.
void Example() {
string s1 = "example";
string& s2 = s1; // s2 is now a reference to s1
}
I would recommend checking out the C++ FAQ entry on references as it's a good introduction to them.