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: 
The answer to „what do I do if a library has a bad interface and I can't change it“ is usually „write a wrapper“. Assuming this is a method of some class `BadLibraryClass`, you could do something like:

```cpp
class Wrapper {
public:
    BadLibraryClass inner;

    setValue(int i) {
        inner.setValue(i); // i is an lvalue
    }
};

```

This is just a crude example. Perhaps `inner` is better off being a pointer, a reference or even a smart pointer. Perhaps you want a conversion operator to `BadLibraryClass`. Perhaps you can use inheritance to expose other methods of `BadLibraryClass`.
**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`.