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: 
Two options:

Use the result of assignment:

```
static int _data;
void myCall() {
  setValue((_data = 3));
}

```

Write a wrapper:

```
struct setValueW {
  int _data;

  // constructor
  setValueW(int _data) : _data(_data) {
    setValue(_data);
  }

  // if you want to call it again
  void operator()() {
    setValue(_data);
  }
};

void myCall2() {
  setValueW(3);
}

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