How do I create a module-local immutable class object?

David Nadlinger see at klickverbot.at
Fri Sep 9 14:47:33 PDT 2011


On 9/9/11 11:45 PM, Andrej Mitrovic wrote:
> So much for that idea, immutable breaks property functions. Take a look:
>
> class Foo
> {
>      this()
>      {
>          value = true;
>      }
>
>      @property bool value() { return true; }
>      @property void value(bool value) { }
> }
>
> void main()
> {
>      auto foo1 = new Foo;
>      auto val1 = foo1.value;
>
>      auto foo2 = new immutable(Foo);
>      auto val2 = foo2.value;  // fail
> }
>
> Is this a known issue or should I file it?

Did you mark the getter const?

David


More information about the Digitalmars-d-learn mailing list