I have a string& parameter, and i want to assign it to string parameter.
How can it be done.
I have a string& parameter, and i want to assign it to string parameter.
How can it be done.
Generally speaking, string& or even const string& is just a name alias and if you have it somewhere in your code, it's equal to
// This means you just create a new ALIAS named "aliased_string"
// for REAL "real_string"
string& aliased_string = real_string;
Now, whenever you make something with your aliased_string, the changes are done directly with your real_string.
Hence, assigning becomes very simple:
// Create a new string
string constructed_string;
// Means the same as "constructed_string = real_string"
constructed_string = aliased_string;
Note, that if you have some function with reference in it's parameter list, the logic remains the same:
void foo (string& aliased_string) { ... }
generally means the same as
void foo () { string& aliased_string = real_string }
where real_string is passed as a parameter.