C++ conversion operator to unsigned long does not work
Martin Sebor
sebor@roguewave.com
Thu Sep 28 07:45:00 GMT 2000
Martin Reinecke wrote:
>
> Hi!
>
> 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 (7.1.5.2) 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
> properly?
Use static_cast<unsigned long>(a) or (unsigned long)a instead.
Regards
Martin
More information about the Gcc-bugs
mailing list