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

```
> 
> Can I change something at the call site to make it work
> 
> 
> 

The problem with your code is that you declared your function to expect a reference, which means the compiler has to prepare the code to allow the function to change whatever you pass into it at the call site. So yes, sure, you can declare a variable, set it to 1 and call your function with it.

Contrast this with a **constant** reference in the declaration, where the compiler knows you won't change it inside the function, and then you can pass a literal in without issues. In fact, any logical, thought out design will make setters accept constant parameters because it won't change them, it will just store a possibly processed value in its state.