but while
int f(int& n)
{
n += 99;
return n; // copies the value referred to by n
}
won't compile in my example from the previous page, the code below will:
string f(string& n)
{
return n += "99";
}
and the signature is the same,both take a reference and return by value! So what is actually happening here?
My current guess is that the first one at the return stage is doing
int ??? = n;
and the other is doing
string ??? = n;
so the only difference must be the overload on operator=
So in the int case the overload must be
int operator=(int,int)
while in the string case is
string& operator=(string,string)
So is this the case? operator= is behaving differently for the primitive types?