I want to establish whether my understanding to some basic C++ reference principles are correct. To my understanding, declaring;
void foo(string &arg); //Means get the memory reference of passed argument
{
cout << arg;
}
string arg;
string& arg1; //Means pass the memory reference of arg
Am I correct?
EDITED
Means
arg1&arg2are references to a variablestrwhich is of the typestring, it means they are just an alias name for variablestr.They Both essentially declare a reference variable as said above it is just a matter of style where the
&is placed.ptris a pointer to a variablestrwhich is of the typestring.Note:
A reference must be initialized to a variable at the time of creation, and it cannot be made to refer any other variable after the initialization. A Reference always remains alias to the same variable. So you should not be just doing just:
The compiler will give you an error for this, something like: