problem about void function

What's the problem of this code,I want to use this function to increment the value of win,but it doesn't work at all.
#include<iostream>
using namespace std;
void plus(int);
int main()
{
int win=0;
cout<<win<<endl;
plus(win);
cout<<win;

system("pause");
return 0;
}
void plus(int a)
{
a++;
}
You're passing a to the function by value, so it makes a copy, increments that copy, and then the copy gets destroyed. You need to pass by reference, like this: void plus(int& a)

http://www.cplusplus.com/doc/tutorial/functions2/
Last edited on
Thanks very much,
I've stuck on this for a long time.
Topic archived. No new replies allowed.