Question: I am calling a function with the signature

```
void setValue(int& data)

```

I would like to pass a literal number to it:

```
setValue(1);

```

But I get:

```
error: invalid initialization of non-const reference of type 'int&' from an rvalue of type 'int'

```

Is there a way I can make this work without changing the function (it's in a library) and without assigning each literal value to a variable?

Answer: 
Assuming `setValue` does not actually modify its argument and just has a wrong signature which you cannot change, here is an approach which is not thread-safe among other things:

```
#include <iostream>

void setValue(int &i)
{
  std::cout << "i = " << i << std::endl;
}

int& evil(int i)
{
  static int j;
  j = i;
  return j;
}

int main()
{
  setValue(evil(1));
  setValue(evil(2));
}

```
AFAIK, references keeps the addresses of the variable. 1 is not variable. It is temporary.

Take a look this article(this is a quote from [this](http://www.cs.fsu.edu/%7Emyers/cop4530/notes/references2.html) site)

> 
> c++11 introduced a new kind of reference variable -- an r-value reference
> 
> 
> 

> 
> To declare one, use && after a type
> 
> 
> 

```
int & // type designation for an L-value reference

int && // type designation for an R-value reference

```

> 
> * L-value references can only refer to L-values
> * R-value references can reference to R-values (temporaries)
> 
> 
> 

```
int x, y, z;        // regular variables

int & r = x;        // L-value reference to the variable x

int & r2 = x + y;   // This would be ILLEGAL, since x + y is an R-value

int && r3 = x + y;  // LEGAL. R-value reference, referring to R-value

```

So you can use (But this is not useful. It may be more useful if you write this in plain without rvalue or lvalue.):

```
void setValue(int&& data)
setValue(1);

```

Or you can use that:

```
void setValue(int& data)
int a = 11;
setValue(a);

```

**Don't forget for second example. If you change the value of `data` parameter. You will have change the `a` variable value.**