Private enum members
d-noob
doesnt at exist.com
Mon Oct 26 05:38:38 PDT 2009
Kagamin Wrote:
> Justin Johansson Wrote:
>
> > enum Color {
> > private UNINITIALIZED = -1,
> > RED, GREEN, BLUE
> > }
>
> It's syntactical ambiguity, I think. There's no much difference between
> private UNINITIALIZED = -1,
> RED, GREEN, BLUE
>
> and
>
> private UNINITIALIZED = -1, RED, GREEN, BLUE
So let's fix it:
enum C {
private:
UNINITIALIZED = -1;
public:
RED, GREEN, BLUE;
}
But even now it's easy to set illegal values in client code:
C c = RED;
c--; // bang!
Gotta love the implicit conversions - this is almost like pointer arithmetics
More information about the Digitalmars-d
mailing list