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:

  1. lvalue reference parameter

    void printint(int& a) {     cout<<a<<endl; } 
  2. rvalue reference parameter

    void printint(int&& a) {     cout<<a<<endl; }     
  3. 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

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -