I read in accelerated c++ that we should pass lvalue to non-const references. Why is that? As far as i know lvalue is the one which can be modified. Please tell me if it has another definition.
I checked it by writing a simple program:
#include<iostream>
#include<vector>
using namespace std;
vector<double> ret()
{
vector<double> d;
return d;
}
void rec(vector<double> &g)
{
cout<<"entered..."<<endl;
}
int main
{
rec(ret());
}
And error is
invalid initialization of non const reference from r value
What meaning do rvalue
and lvalue
have here? d
is a local variable in ret()
and it is passed by value so it does not have dangling issues.
What happens when rec(ret())
is called and
explain to me how rec()
sends its argument.