I'm currently having a bug I don't quite understand:
The variable animationSheet is declared as follows:
Code:
vector<spriteSheet *> animationSheet;
The first version of the problematic code was like this:
Code:
for (int idx = 0; idx < animationSheet.size(); idx++)
{
delete animationSheet[idx];
}
It worked, but during compilation, there was this warning:
Quote:
warning: comparison between signed and unsigned integer expressions
|
So we changed the code to this:
Code:
for (unsigned int idx = 0; idx < animationSheet.size(); idx++)
{
delete animationSheet[idx];
}
This however caused problems in the program because spriteSheets were deleted that shouldn't have been deleted (with numbers like 65536 for example)
I changed the code like this:
Code:
int idx=0;
for ((unsigned int) idx; idx < animationSheet.size(); idx++)
{
delete animationSheet[idx];
}
But it has no effect.
I would like to understand what's really going on here and how to have it work without warnings.
vector::size seems to return a size_type.
Which I suppose is the same as
size_t, i.e an unsigned integer.
int seems to be a signed int by default.
What happens in each case during the comparison?
And how does the "animationSheet[idx]" use idx? as signed or unsigned integer?