Const, strings, and other things.

Janice Caron caron800 at googlemail.com
Mon Nov 12 23:52:57 PST 2007


In C++ (and, I believe, D), it is possible for a statement like

    a = b;

to modify b. That's because the argument to operator=() or opAssign()
could be a non-const reference. You could argue that this would be a
silly thing to do, but auto_ptr<T> does that by design.

Likewise, it is possible in D for

    a[n] = b;

to modify b (and even n). You could argue that a function /shouldn't/
do stuff like that - but what if it does it by accident? As in,
because of a bug? const is your only guarantee that that won't happen.



More information about the Digitalmars-d mailing list