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.