0

I'm trying to compile something like this:

int f(int a){
    return a+2;
}

void g(int& a){
    a++;
}

int main(){
    int a=5;
    g(f(a));
} 

but I get the error:

error: invalid initialization of non-const reference of type 'int&' from an rvalue of type 'int'

at g(f(a));

Why? How could I solve it?

Don't Panic
  • 41,125
  • 10
  • 61
  • 80
sworwitz
  • 19
  • 7

0 Answers0