Hi,

Could someone explain the logic behind the following:

"Arguments that correspond to non-const reference parameters must be
lvalues-that is they must be non-temporary objects. Arguments that are
passed by value or bound to a const reference can be any value"

Suppose a function returns an empty vector
vector<double> emptyvec()
{
 vector <double>v;
return v;
}

Now calling another function which accepts const reference as a parameter
does not error out but function which accepts non-const reference parameter
errors when passing emptyvec() to it.Why? I do not understand the concept.

This emptyvec() function returns a copy of v to the caller and destroys v
which is local to emptyvec(). So why cannot this copy be passed without
error as a non-const reference. Why is the behavior different between const
and non-const reference.?

-- 


Reply via email to