immutable array in constructor

tsbockman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 17 04:24:19 PDT 2016


On Thursday, 17 March 2016 at 10:11:43 UTC, Jeff Thompson wrote:
> This is a simplified example from a larger class I have where I 
> need an immutable constructor. This is because I need to 
> construct an object an pass it to other functions which take an 
> immutable object. So, how to keep an immutable constructor?

The "mutable object" the compiler is complaining about is the 
instance of C being constructed, not the array.

Change `new C(array)` to `new immutable(C)(array)` and it should 
work.


More information about the Digitalmars-d-learn mailing list