On Sat, 03 Jan 2015 15:56:58 +1030
ted via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:

> Ironically, I'm trying to use const in an effort to understand it...but 
> there seems to be an unusual amount of pain until I grok it.
just remember that `const` "infects" everything down to the bytes when
it's applied. and it's forbidden to overwrite `const` vars with
different values.

in your canse it "infects" your `A` struct, effectively converting it
to `const A` (with `const int someInt`). and as you can't change
"consted" value, and structs are `memcpy()`ed... compiler tracked that
down and refused to do it.

so you don't really need `const` fields in D. you can make getters
`const` though, so that they can be used on `const MyStruct` instances.

so two rules should help you here:
1. it's forbidden to overwrite `const` vars with new values.
2. `const` will infect everything down to bytes.

maybe this will help you like it helps me. ;-)

Attachment: signature.asc
Description: PGP signature

Reply via email to