How can I use structs in a named enum?
simendsjo
simendsjo at gmail.com
Wed Feb 29 03:15:35 PST 2012
.. 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..?
More information about the Digitalmars-d-learn
mailing list