I am trying to understand a program that includes the following definition for a function f
void f(String S, const String& r)
{
}
Here String in the argument stands for the class. I am confused by the difference between the definitions of these two arguments: "String S" and "const String & r". S should represent an object of class String, then what about r?
In more detail, f is defined as
void f(String S, const String& r)
{
int c1 = S[1]; // c1=s.operator[](1).operator char( )
s[1] ='c'; // s.operator[](1).operator=('c')
int c2 = r[1]; // c2 = r.operator[](1)
r[1] = 'd'; // error: assignment to char, r.operator[](1) = 'd'
}
This piece of code shows how the operator is overloaded, but these comments do not help me much. For example, why r [1] = 'd' is not correct? Thanks for helping me figure this out.
source
share