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

Janice Caron caron800 at googlemail.com
Tue Feb 19 14:18:29 PST 2008


On 19/02/2008, Derek Parnell <derek at psych.ward> wrote:
> Ok given this position and that 'string' is 'invariant(char)[]' then
>
>    string s;
>
> makes 's' a reference to an immutable array,

No, s is an array of immutable chars. Put another way, as I am sure
you are well aware, s is a value type, whose layout is

    struct
    {
        invariant(char)* ptr;
        uint length;
    }


> If so, does that mean that I cannot bind 's' to another
> literal

s isn't a reference, and so the concept of "binding" doesn't make
sense for it. What you can do is reassign it with another value.
Basically, everything works, exactly as is it should.



More information about the Digitalmars-d mailing list