C++ conversion operator to unsigned long does not work
Thu Sep 28 07:45:00 GMT 2000
Martin Reinecke wrote:
> gcc-2.95.2 and the current CVS version fails to compile the following code:
> int main()
> int a = 1;
> unsigned int b = unsigned long(a);
This is in error, only a simple-type-specifier (126.96.36.199) is allowed in a
functional cast (5.2.3).
> gcc seems to choke because the name of the type to which a should be converted consists of two tokens.
> I'm not absolutely sure that the code above is legal C++; but if not, how does one write such a conversion
Use static_cast<unsigned long>(a) or (unsigned long)a instead.
More information about the Gcc-bugs