Created
April 2, 2018 12:00
-
-
Save run-dlang/8282437e93c3bfe2aa003294bf2f2032 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