Class References
John Colvin
john.loughran.colvin at gmail.com
Mon Oct 28 05:10:35 PDT 2013
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);
}
More information about the Digitalmars-d-learn
mailing list