The compiler warning is correct - you cannot do this. i will most likely be overwritten at some time.
Or do
int f() {
or
int &f( int &i ) { // accept reference // actually, in the case of modify-and-return like this, // you should call by value and return by value without // using any references. This is for illustration. i = 5; return i; } int main(){ int i cout<<f(i)<<endl; }
Potatoswatter
source share