Getting an access violation error when I get to the array sort code...

Here's the code. Any thoughts?

// sort the shape arrays by area
	for(int i = 0; i < total - 1; i++) 
		{
			for (int j = i; j < total; j++) //start at i
			{
				if (shapeArray[j + 1]->area() < shapeArray[j]->area()) // sort order
				{ 
				tempArray[j] = shapeArray[j]; // swap elements
				shapeArray[j] = shapeArray[j + 1];
				shapeArray[j + 1] = tempArray[j];
				}
			}
		}

Well, it looks like you can access a member outside of the array:

shapeArray[j + 1]

because

for(int j = i; j < total; j++)

allows it to get to the final member, then you can step one further, putting you outside of the array.

Looks like you tried to prevent this in the first array taking total = 1

for(int i = 0; i < total - 1; i++)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.