Effect of declaring a class immutable ?

ArturG via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 26 07:46:59 PDT 2016


On Thursday, 26 May 2016 at 14:12:23 UTC, chmike wrote:
> I couldn't find any information about this on the dlang web 
> site.
>
> What is the effect adding the immutable attribute to a class 
> like this
>
> immutable class MyClass { ... }
>
> The compiler doesn't complain.
> Will it add the immutable attribute to all members ?

auto mc = new MyClass;

typeof(mc.someFieldOrFun).stringof.writeln; says yes

and if you define opCall you need to use
auto mc = new immutable MyClass;


More information about the Digitalmars-d-learn mailing list