Programming in D, page 155. shared static this() fails
H. S. Teoh
hsteoh at qfbox.info
Tue Jul 29 23:48:58 UTC 2025
On Tue, Jul 29, 2025 at 10:57:50PM +0000, Brother Bill via Digitalmars-d-learn wrote:
> ```
> import std.stdio;
>
> immutable int[] i;
>
> shared static this() {
> writeln("In shared static this()");
> i ~= 43;
> }
`i` is immutable, so it's illegal to use mutating operations like ~= on it.
But since you're inside a static module ctor, you can assign to the
array instead:
i = [ 43 ];
should work.
T
--
Why does this impressionist painting look like coins falling from the sky? It's Cloud Monet.
More information about the Digitalmars-d-learn
mailing list