Using typedef'd uint causes an error, whereas "unsigned int" does not ...?

For some reason, when I define a variable as "uint" instead of "unsigned int" in my program, these are errors. This seems strange because uint typedef'd:

typedef unsigned int uint; 

... so I think I could use these two interchangeably. More precisely, I assign the result of a function that returns "unsigned int" to the uint variable, then using this uint in the vector resize call ... at this point, these are errors. Those. 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 in which he is mistaken is the line myVect.resize.

Obviously, I already have a solution, but I would like to understand WHY this is happening, since I am rather puzzled. Does anyone have any idea?

PS - If someone thinks this may matter, I use gcc v4.1.2 for fedora 15 ... and the include file that defines uint is / usr / include / sys / types.h.

+7
source share
2 answers

I assume that there is another uint in the system. Try renaming your code to something unusual, or even better wrap it in a namespace.

 namespace MY { typedef unsigned int uint; } for (MY::uint i = 0; .... 
+6
source

I assume that he is trying to create a β€œhierarchy” of some kind.

In other words, we have:

 typedef unsigned int size_t; typedef unsigned int uint; 

If size_t is "more specific" than the general unsigned int , then it makes sense to prevent it from being converted to uint , which may be "more specific" than any old unsigned int .

I would expect this to be a warning if anything, although not an error ...

-one
source

All Articles