enum question

Ali Çehreli acehreli at yahoo.com
Tue Mar 18 15:51:21 PDT 2014


On 03/18/2014 01:40 PM, Eric wrote:

 > Apparently you can't pass an enum as a reference,

It is possible as seen in the following code.

 > I have read on this forum that someday enums may be able to be
 > made with class elements.

Someday is today! :)

class C
{
     int i;

     this(int i)
     {
         this.i = i;
     }
}

enum E : C
{
     one = new C(1),
     two = new C(2)
}

void foo(ref E e)
{
     e = E.two;
}

void main()
{
     auto e = E.one;
     foo(e);
     assert(e == E.two);
}

Ali



More information about the Digitalmars-d-learn mailing list