1.
Strings "First " and "Second " written in 15, 16 lines are hardly compiled into program, so they are readonly.
When you write
void entervalues(string& vect,
, you allow this function to modify argument. But argument is readonly. Thit is reason of error.
So you have to add const keyword.
You can rewrite is as
1 2
|
string s = "First";
entervalues("First ", U);
|
In this case readonly string is copied into local variable "s", which is readwrite. After it you can use entervalues without const keyword.
2.
If you don' put &
1 2 3 4 5 6 7 8
|
void f1(string s1)
{
}
void f2()
{
string s2 = "text";
f2(s2);
}
|
string s2 is copied for f1 and named s1. When you change s1, s2 is not modified.
If you put
1 2 3 4 5 6 7 8
|
void f1(string s1&)
{
}
void f2()
{
string s2 = "text";
f2(s2);
}
|
s1 is the onher name for s2. When you change s1, you change s2.
Adding & is preferrable in complex, time extreme applications, because every copying of string take some time, which make system slower.
3. Actually, you can write
void entervalues(string vect,
In this case readonly strings "Second " and "First " will be copied into local valiable of entervalues(...). It makes program simplier, but 2 nanoseconds slower.