Qualified destructors / immutable objects
Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 13 08:36:53 PDT 2015
On Friday, 12 June 2015 at 15:36:22 UTC, anonymous wrote:
> no need for ~this() to modify immutable data:
>
> class C {
> int a;
>
> this(int a) {
> this.a = a;
> }
> }
>
> struct S {
> C elem = new C(42);
> }
>
> void main() {
> import std.stdio;
> immutable(S) s1;
>
> // Error: cannot modify immutable expression s1.elem.a
> // s1.elem.a = 43;
>
> writeln(s1.elem.a);
>
> S s2;
> s2.elem.a = 123;
> writeln(s1.elem.a);
> }
>
> Prints:
> 42
> 123
Is there an existing issue on issue.dlang.org? If not can you
report it
More information about the Digitalmars-d-learn
mailing list