Construct immutable member in derived class

Timoses timosesu at gmail.com
Wed Apr 4 10:11:37 UTC 2018


Example:

```
class A
{
     immutable int i;

     this(){}
}

class B : A
{
     this()
     {
      	this.i = 3;
     }
}

void main()
{
     auto b = new B;
}
```

throws:
> Error: constructor `onlineapp.A.this` missing initializer for 
> immutable field i
> Error: cannot modify immutable expression this.i

Why can't I initialize the immutable member in the derived class?


More information about the Digitalmars-d-learn mailing list