Jump to content
  • Advertisement
Sign in to follow this  
manningb57

Vector problems in C++ class

This topic is 1927 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!