Returning (by) Reference
Consider the following function:
float & min(float&a,flo at&b)
{
if(a>b)
return a;
else
return b;
}
"A function call,min(x,y)wi ll yield a reference to either a or b depending upon which one is lesser than the two.This means that this function can appear on the left hand side of an assignment statement since it returns a reference to a variable.That is,
min(x,y) = -5;
assigns -5 to the lesser of the two,x&y."
What does this mean?
Consider the following function:
float & min(float&a,flo at&b)
{
if(a>b)
return a;
else
return b;
}
"A function call,min(x,y)wi ll yield a reference to either a or b depending upon which one is lesser than the two.This means that this function can appear on the left hand side of an assignment statement since it returns a reference to a variable.That is,
min(x,y) = -5;
assigns -5 to the lesser of the two,x&y."
What does this mean?
Comment