digitalmars.D - Re: Private enum members
- Kagamin <spam here.lot> Oct 26 2009
- d-noob <doesnt exist.com> Oct 26 2009
- Kagamin <spam here.lot> Oct 26 2009
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
Oct 26 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
Oct 26 2009
d-noob Wrote:So let's fix it: enum C { private: UNINITIALIZED = -1; public: RED, GREEN, BLUE; }
See enums with virtual methods http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html
Oct 26 2009