On Monday, 28 October 2013 at 11:22:03 UTC, Jeroen Bollen wrote:
Is it possible in D to create an enum of class references?
Something around the lines of:

enum ClassReferences : Interface {
    CLASS1 = &ClassOne,
    CLASS2 = &ClassTwo
}

Short answer: No

Long answer: the enum values must be compile-time constants, that's what enums are all about. Addresses and references are not compile-time constants.

What is the use case? There is probably a simple way of doing what you want. Why not:

interface Interface{}
class ClassOne : Interface {}
class ClassTwo : Interface {}

struct ClassReferences
{
    Interface classOne, classTwo;
}

void main()
{
    auto c1 = new ClassOne();
    auto c2 = new ClassTwo();

/* either this*/
    ClassReferences crs;
    crs.classOne = c1;
    crs.classtwo = c2;
/* or this */
    auto crs = ClassReferences(c1,c2);
}

Reply via email to