const objects
Dom DiSc
dominikus at scherkl.de
Sun Aug 17 22:15:36 UTC 2025
On Sunday, 17 August 2025 at 15:09:30 UTC, H. S. Teoh wrote:
> If you want to pass an immutable pointer to S2.this, you need
> to use `inout`:
>
> ```d
> struct S2
> {
> int* my_x;
> this(inout(int)* x) inout { my_x = x; }
> }
>
> void main(string[] args) {
> immutable int i = 1;
> auto s2 = immutable(S2)(&i); // OK
> }
> ```
Ah! I thought of inout, but it is not allowed on member
variables. I didn't know that I can mark the constructor inout.
Many thanks, this works!
More information about the Digitalmars-d-learn
mailing list