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));
}

```
When you declare the argument as being an int&, you are saying that the function called can change the value ***and the caller will see the change***.

So it is no longer valid to pass a literal value then because how could the function possibly change the given value of a literal?

If you don't want the `setValue` to be able to change the given value, make the argument either be an `int` or `const int&`. And if you ***do*** want the `setValue` function to be able to change the value, then the caller must declare a non-const ***variable*** to hold the int and pass in that.