initializing immutable structs

Paul D. Anderson paul.d.removethis.anderson at comcast.andthis.net
Thu Mar 25 22:35:29 PDT 2010


I want to initialize an immutable struct but I'm encountering two difficulties and I can't find the answer in the documentation. (Wouldn't it be nice if someone wrote a book?)

The primary difficulty is that I can't use a static initializer but need to use a constructor instead. But the constructor isn't allowed as it's non-constant expression. How do I declare the struct variable and initialize it separately?

The second difficulty is that when I declare it immutable I get a "can't implicitly convert an expression of type X to to immutable X" error. I tried an explicit cast and that didn't work.

I'm reasonably certain that this is a common idiom. I'm just trying to declare some constants to use later. What am I missing?

Thanks,

Paul

1st Difficulty -- I can't 


More information about the Digitalmars-d-learn mailing list