c++ - Rvalue and Lvalue References -
i have function printint below.
void printint(const int& a) { cout<<a<<endl; } when call function using following arguments like
int a=5; printint(a); printint(5); it works perfectly. when change function definition
void printint(int& a) { cout<<a<<endl; } this gives error call printint(5). question why const int& both lvalue , rvalue reference whereas int& lvalue reference. far know int&& rvalue reference. how single & can refer rvalue reference?
to summarize problem:
lvalue reference parameter
void printint(int& a) { cout<<a<<endl; }rvalue reference parameter
void printint(int&& a) { cout<<a<<endl; }both lvalue , rvalue. how?
void printint(const int& a) { cout<<a<<endl; }
const int& lvalue reference. thing language specifies can bind rvalues. int& lvalue reference, cannot that. why first version works , second doesn't.
Comments
Post a Comment