Why won't this simple function work?

I'm trying to make a function that takes a reference to a vector as an argument, and reverses its elements. This is my code:
1
2
3
4
5
6
7
void ref_reverse(vector<int>& vect)
{
	for(int i = 0; i <= (vect.size() / 2); i++)
	{
		swap(vect[i], vect[(vect.size()-i)]);
	}
}

I got an error message when running the program: "Debug Error! R6010 abort() has been called". I can't figure out what is wrong. If anyone could help me understand what is wrong with my code, I would appreciate it.
Let assume that i == 0 then you are trying to access element vect[(vect.size()-0)] that does not exist.
Thank you! I fixed it by changing [(vect.size()-i)] to [(vect.size()-(i+1))].
Topic archived. No new replies allowed.