I'm trying to figure out why I should convert all my unsigned ints/shorts to size_t.
I'm doing the things below but I'm not sure which one to use and which type to iterator my for-loop with:
unsigned short Size()
{
return vector.size();
}
int Size()
{
return vector.size();
}
unsigned int Size()
{
return vector.size();
}
size_t Size()
{
return vector.size();
}
for (unsigned short I = 0; I < Size(); I++)
{
//...................
}
I looked up the difference and it says that the size can vary from machine to machine and that size_t is the sizeof a pointer but then I was thinking that there would be no way someone would allocate a vector of 4.2b so I decided 65535 is enough so I used unsigned short but then I thought maybe that's too small so I decided unsigned int then came across size_t and now I'm confused which to use between the them all. The short? int? unsigned int? unsigned short? size_t? long?
As for my pointer question, after using delete[]
on a pointer, should I then set that pointer to = 0? Example:
char* Meh = new char[1024];
delete[] Meh;
Meh = 0;
also why does the compiler allow me to do char Meh[vector.size() + 1]
without having to use the new keyword?