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: 
> 
> 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.
**No, you can't.**

An lvalue reference like that binds to a variable (roughly speaking).

Your literal is not such a thing. It never had a name, and may not even have a home in memory.

Your two options are the two things you ruled out, I'm afraid.

---

For what it's worth, this is not your fault: that is a rather poor setter. It should take `const int&` (which will automatically *create* a nice temporary variable for you out of the literal!), or even just `const int`.