. , immutable. , , . , , , , , , const immutable . . .
struct Foo
{
int i;
this(int j) { i = j; }
this(Foo rhs) { this = rhs; }
}
void main()
{
immutable f = Foo(5);
}
. , , - postblit, const immutable (-, , - , - , , , , , ). , postblit, ( , , , ).
, , . , , immutable, immutable ( structs, , , , , ):
class Foo
{
int i;
this(int j) { i = j; }
}
void main()
{
auto f = new immutable Foo(5);
}
:
q.d(10): Error: mutable method q.Foo.this is not callable using a immutable object
q.d(10): Error: no constructor for Foo
. immutable
class Foo
{
int i;
this(int j) immutable { i = j; }
}
, , Foo, immutable, , ( ). , . .
class Foo
{
int i;
this(int j) { i = j; }
this(int j) immutable { i = j; }
}
, , . , , pure.
class Foo
{
int i;
this(int j) pure { i = j; }
}
, , ( pure , , , ) , Foo , , Foo, , const immutable . , , pure, , , , , .
, , const immutable, . , , const immutable .