Member field of type nested struct must be initialized in constructor: Why?

Inkrementator anon at anon.org
Mon Oct 23 17:45:40 UTC 2023


On Sunday, 22 October 2023 at 23:49:40 UTC, Paul Backus wrote:
> Nested structs contain a context pointer that needs to be 
> initialized at runtime. If you don't initialize them, the 
> pointer gets set to `null`, and the struct will not be able to 
> access its context.

I see, thanks for the explanation.

> Using `.init` doesn't fix this because `.init` is determined at 
> compile time, and also has `null` in place of the context 
> pointer.

In my case, it makes sense to not initialize the object, so this 
isn't an issue. Void-initialization would probably be better to 
document my intent, but the compiler won't let me do that.


More information about the Digitalmars-d-learn mailing list