Why can't we define re-assignable const reference variable?

Janice Caron caron800 at googlemail.com
Wed Feb 20 13:36:31 PST 2008


On 20/02/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>  bound const Class c4 = new Class(); // bound (ie const) ref to const data

Wouldn't the word "const" be superfluous in that example, since
constancy is transitive? (If the reference is constant, the data
/must/ be).

It's an interesting idea, but I think, in general, if the compiler
sees an array like

    const(T)[] x;

then it has to mean that the array's contents are not modifiable. That
rule shouldn't depend on T, it should simply be true always. Ditto all
other collections.



More information about the Digitalmars-d mailing list