This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Prohibit enum <-> int mixup


On 29 January 2011 22:33, Jonathan Wakely wrote:
> On 29 January 2011 20:48, Enrico Weigelt wrote:
>>
>> I'm using C++. It already warns me about a few things, eg. missing
>> case's in switch statements. But it still accepts assigning
>> enum to int and vice versa.
>
> No it doesn't, C++ allows enums to be assigned to ints but not the
> other way around.
>
> enum e { val };
> e var = 0;
>
> e.cc:2: error: invalid conversion from ‘int’ to ‘e’

Technically what is allowed is implicit conversion from enum to int.
In C++0x you can define a scoped enum which doesn't allow the
conversion.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]