Is this use of enum ok?



 DEVELOP > c-Plus-Plus > Is this use of enum ok?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 18 Jan 2008 12:15:34 AM
Object: Is this use of enum ok?
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
.

User: "Jensen Somers"

Title: Re: Is this use of enum ok? 18 Jan 2008 12:51:11 AM
wrote:

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
.
User: "Pete Becker"

Title: Re: Is this use of enum ok? 18 Jan 2008 06:14:50 AM
On 2008-01-18 01:51:11 -0500, Jensen Somers <jensen.somers@gmail.com> said:


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.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER