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

```
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`.