signed/unsigned int and vector::size()
I'm currently having a bug I don't quite understand:
The variable animationSheet is declared as follows: Code:
vector<spriteSheet *> animationSheet; Code:
for (int idx = 0; idx < animationSheet.size(); idx++) Quote:
Code:
for (unsigned int idx = 0; idx < animationSheet.size(); idx++) I changed the code like this: Code:
int idx=0; 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? |
There are a number of ways of doing this without getting a warning.
First method is to use a smart pointer class and then you never have to worry about cleaning up pointers. Second method is to not use pointers and instead use instances of classes( yet this may not be what you want). Third use the for_each function Code:
#include <algorithm> Code:
... Code:
... |
All times are GMT -5. The time now is 07:36 PM. |