Skip to content

Instantly share code, notes, and snippets.

@ncaq
Created November 1, 2013 09:28
Show Gist options
  • Save ncaq/7263027 to your computer and use it in GitHub Desktop.
Save ncaq/7263027 to your computer and use it in GitHub Desktop.
structではできるのに,classでできないのはなぜだ?
struct S
{
this(in int val)inout
{
val_ = val;
}
private int val_;
}
class C
{
this(in int val)inout
{
val_ = val;
}
private int val_;
}
class C2
{
this(in int val)
{
val_ = val;
}
this(in int val)immutable
{
val_ = val;
}
private int val_;
}
void main()
{
S ms = S(0);//OK
immutable S ims = S(0);//OK
C mc = new C(0);//NG
immutable C imc = new immutable C(0);//NG
C2 mc2 = new C2(0);//OK
immutable C2 imc2 = new immutable C2(0);//OK
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment