random number with vectors

im trying to make a vector of random numbers, but this isnt working

1
2
3
4
5
6
7
8
9
void make_vec(vector <int> list, int l)
{
	for (int i=0; i < l; i++)
	{
		int hold = rand();
		list.push_back(hold);
	}
	return;
}


any tips on what's wrong
Are you calling this function somewhere else in your program like this:

1
2
3
vector<int> intVec;
make_vec(intVec, 10);
//do something with the contents 


In this case, because you are passing by value, the local variable list in your function will be a copy of the original argument, and adding entries to it will not change the variable that is used as the argument (intVec in my example). Try changing make_vec to take a reference to a vector<int> instead.
you are a beautiful person. I've been forgetting to pass vectors by reference all night. thank you greatly.
Topic archived. No new replies allowed.