Looping Iterator problem

I have code which looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
void Gear::equipArmor(Armor* &armor)
{
	bool found = false;

	for(int i = 0; i < (int)Armors.size(); ++i)
	{
		if (armor->returnArmorType() == Armors[i]->returnArmorType())
		{
			found = true;
		}
	}
}


However when my program reaches the for loop, the int i does not equal to zero but to -858993460. What could be the problem?
My guess would be you're inspecting the variable before it's initialized and it isn't actually a problem.
Your problem is that you're using an integer for something an unsigned integer should be doing. You should never have a negative size. Next, make sure your stuff is initialized before using them. Lastly, why are you using a reference to a pointer? Hopefully, your compiler is smart enough to realize what you're doing and will optimize it to save an extra indirection.
Topic archived. No new replies allowed.