Created
April 2, 2018 11:36
-
-
Save run-dlang/83756973012fcb4fec2660a39ffdad90 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
struct B | |
{ | |
int a; | |
int* t; | |
this(int a) immutable | |
{ | |
this.a = 7; | |
} | |
this(int a) | |
{ | |
this.a = 10; | |
} | |
} | |
void main() | |
{ | |
B a = immutable B(2); | |
writeln(a.a); | |
a.a = 4; | |
immutable B a2 = immutable B(3); | |
writeln(a2.a); | |
//a2.a = 3; // error : cannot modify | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment