digitalmars.D - My problem with const
- Freddy (19/19) Sep 04 2015 I love the way D does transitive const and immutable but i have a
- Adam D. Ruppe (6/7) Sep 04 2015 That's due to the nature of structs - you would be overwriting a
I love the way D does transitive const and immutable but i have a problem when i use const a struct field. --- struct MyStruct { int a; const int b; } struct Range { MyStruct front; void popFront() { front = MyStruct(2, 3); } enum empty = false; } --- This sample doesn't compile.
Sep 04 2015
On Friday, 4 September 2015 at 23:26:39 UTC, Freddy wrote:This sample doesn't compile.That's due to the nature of structs - you would be overwriting a const field. Const fields should probably be avoided since they aren't all that useful. You could instead do a const getter property for it without a corresponding setter, then make the actual data private.
Sep 04 2015