I'm trying to create a vector which contains several rectangles (blockRect) in the block class, when the third rectangle (blockRect) in the vector array hit another rectangle (endRect) defined in another class, it (the third blockRect in the vector) should be deleted in the vector, but it gives me a error: vector subscript out of range, I can't figure out why, any help please?
this is the code which I try to delete the third blockRect in the vector (there is 4 blockRect in Vec1, and Vec 2 basicly contains endRect for collision):
for (int i = 0; i < Vec2.size(); i++) {
if (Vec2.endRect.getGlobalBounds().intersects(blocksClass.Vec1[2].blockRect.getGlobalBounds())) {
blocksClass.Vec1.erase(blocksClass.Vec1.begin() + 2);
}
}