Error:Vector out of range using Class Template

I have found where in the program it is giving the error but can not for the life of me figure out why, can anyone help.

I am getting a debug assertion failure
Expression: Vector subscript out of range
Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void Student::SortCourses()
{
	Course *tempCourse = new Course;

	for(int i = 0; i < (int) mCoursesEnrolled.size(); i++)
	{
		for(int j = 0; j < (int) mCoursesEnrolled.size(); j++)
		{
		     if(mCoursesEnrolled[j]->GetCourseNum() > mCoursesEnrolled[j + 1]->GetCourseNum())//this is where the program fails at runtime
			{
				tempCourse = mCoursesEnrolled[j];
				mCoursesEnrolled[j] = mCoursesEnrolled[j + 1];
				mCoursesEnrolled[j + 1] = tempCourse;
			}
		}
	}
}
Run through the for loop on line 7 in your head, looking at line 9/12/13 in particular.
Thanks, I figured it out, it is obvious, oh well it usually is.
Topic archived. No new replies allowed.