For some reason, when I define a variable as "uint" instead of "unsigned int" in my program, it errors. This seems strange, because uint is typedef'd as:
typedef unsigned int uint;
...so I would think that I could use the two interchangeably. To be more exact, I am assigning the result of a function which returns "unsigned int" into a uint variable, then using that uint in a vector resize call... at which point it errors. Ie, my code looks something like this:
unsigned int getUInt()
{
return 3;
}
int main(void) {
vector<vector<float> > vectVect(100000);
for(uint i = 0; i < vectVect.size(); ++i)
{
vector<float>& myVect = vectVect[i];
uint myUnsignedInt = getUInt();
myVect.resize(myUnsignedInt);
}
cout << "finished" << endl;
}
...and the line it errors at is the myVect.resize line.
Obviously, I already have a solution, but I'd like to understand WHY this is happening, as I'm pretty baffled. Anyone have any ideas?
PS - In case anyone thinks it may matter, I'm using gcc v4.1.2 on fedora 15... and the include file which defines uint is /usr/include/sys/types.h.
Unsigned Integers (often called "uints") are just like integers (whole numbers) but have the property that they don't have a + or - sign associated with them. Thus they are always non-negative (zero or positive). We use uint's when we know the value we are counting will always be non-negative.
There is no difference. unsigned and unsigned int are both synonyms for the same type (the unsigned version of the int type).
Yes, size_t is guaranteed to be an unsigned type.
Unsigned int data type in C++ is used to store 32-bit integers. The keyword unsigned is a data type specifier, which only represents non-negative integers i.e. positive numbers and zero.
My guess is that there is another uint in the system. Try renaming yours to something unusual or even better wrap it in a namespace.
namespace MY {
typedef unsigned int uint;
}
for (MY::uint i = 0; ....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With