Simple immutable example doesn't work - why???

Louis Berube louis.p.berube at gmail.com
Mon Nov 11 17:15:01 PST 2013


Thanks, I think I understand. Now, how about an array of 
immutables:

immutable class Test
{
     public:
         this(in uint value)
         {
             this.value = value;
         }
         unittest
         {
             auto t = new immutable Test(4);
             assert (t.value == 4);
         }
         unittest
         {
             auto tarray = new immutable(Test)[3];
             tarray[0] = new immutable Test(4);
                                     // "Error: cannot modify
                                     // immutable expression
                                     // tarray[0]"
         }
     private:
         uint value;
}

I thought the parantheses in the array declaration would do the 
trick, but apparently not.


More information about the Digitalmars-d-learn mailing list