Wanting an immutable associative array in a class

bearophile bearophileHUGS at lycos.com
Thu Jul 29 19:55:35 PDT 2010


RedZone:
> But it would be nice if I could have the array reference itself be immutable
> and not just the array's contents.  Is there any way I could do this?

Let's say your code is as your second example:

class Foo {
    private:
        immutable int[string] bar;

    public:
        this() {
            bar = ["AB":1, "CD":2, "EF":3];
        }
}

void main() {
    auto f = new Foo;
}


How can you change the array reference outside the class constructor?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list