immutable array in constructor

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 17 11:46:57 PDT 2016


On 03/17/2016 09:32 AM, Jeff Thompson wrote:
> On Thursday, 17 March 2016 at 11:27:01 UTC, Rene Zwanenburg wrote:
>> 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?
>>
>> In that case, new immutable C() should work I believe. Also, if you
>> mark the constructor as pure, new C() should be implicitly convertible
>> to an immutable C.
>
> new immutable C() worked! Thanks for the insight.

In case it's useful to others, I have qualified constructors covered at 
the following link (without the compilation error that you've faced but 
still pointing out the fact that the mutable constructor may be called 
unintentionally):

 
http://ddili.org/ders/d.en/special_functions.html#ix_special_functions.qualifier,%20constructor

Ali



More information about the Digitalmars-d-learn mailing list