Is this use of enum ok?

P

pauldepstein

Is there any problem with this code?

class A
{
public:
enum B {C=-1, D = 1, E=2, F = 3, G = 4};


//
//
};

I ask because I've never seen a negative enum value before.

Thanks,

Paul Epstein
 
J

Jensen Somers

Is there any problem with this code?

class A
{
public:
enum B {C=-1, D = 1, E=2, F = 3, G = 4};


//
//
};

I ask because I've never seen a negative enum value before.

Thanks,

Paul Epstein

In C++ enumerator values can be negative. I think the only problem will
occur if you try to use bitwise operations on them, where you can loose
the negative sign.

- Jensen
 
P

Pete Becker

In C++ enumerator values can be negative. I think the only problem will
occur if you try to use bitwise operations on them, where you can loose
the negative sign.

Doing bitwise operations on negative values, whether or not they're
enumerations, is dicey. In order to know what the result should be, you
have to know how the values are represented.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top