How can I use structs in a named enum?

Jonathan M Davis jmdavisProg at gmx.com
Wed Feb 29 09:38:20 PST 2012


On Wednesday, February 29, 2012 12:15:35 simendsjo wrote:
> .. That is >> enum E : Struct {}
> 
> struct S {
> int a;
> }
> 
> // ok
> enum E : S {
> a = S(1),
> }
> 
> // Error: need member function opCmp() for struct S to compare
> /*
> enum E2 : S {
> a = S(1),
> b = S(2)
> }
> */
> 
> struct S2 {
> int a;
> int opCmp(ref const S2 other)
> {
> return a == other.a ? 0 : (a < other.a ? -1 : 1);
> }
> }
> 
> // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable
> using argument types (E3)
> // Error: cast(const(S2))S2(1) is not an lvalue
> // Error: function opcmp.S2.opCmp (ref const(S2) other) is not callable
> using argument types (E3)
> // Error: cast(const(S2))S2(1) is not an lvalue
> enum E3 : S2 {
> a = S2(1),
> b = S2(2)
> }
> 
> void main() {
> }
> 
> 
> So E3 is passed as the parameter to S2.opCmp..?

http://d.puremagic.com/issues/show_bug.cgi?id=4423

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list