Sign in to follow this  

Vector problems in C++ class

This topic is 1715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been having a problem with the vector index , saying that the vector subscript is out of range. I know where the problem in the code is originating, however, I have no idea why or how the index is getting out of range. This is a DarkGDK project which I don't know will make any difference in helping me with it.

 

Here is the code that I believe is causing it:

		else
		{
			boy.setImageIndex(
				(boy.getImageIndex()+1 % (boy.getVectorSize())));
			car.display(dbMouseX(), dbMouseY());
			boy.follow(car);
		}

There are five indices in the vector from 0 to 4. The getVectorSize function is nothing more than vector.size(). Here is the function getImageIndex code:

int Sprite::getImageIndex() const
{
	if(images.size() != 4)
	return imageIndex;
}

Any help will be greatly appreciated. If you need any other information, please let me know and I will get it.

Edited by manningb57

Share this post


Link to post
Share on other sites

This topic is 1715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this