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

Louis Berube louis.p.berube at gmail.com
Mon Nov 11 16:36:43 PST 2013


Simple example:

// file immutable_example.d

immutable class Test
{
     public:
         this(in uint value)
         {
             this.value = value;
         }

         unittest
         {
             auto t = new Test(4);   // "Error: immutable method
                                     // 
immutable_example.Test.this is not
                                     // callable using a mutable 
object"
             assert (t.value == 4);
         }

     private:
         uint value;
}

Assuming this is not a compiler issue, what am I missing? Integer 
literal is about as immutable as it gets.


More information about the Digitalmars-d-learn mailing list