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

Steven Schveighoffer schveiguy at yahoo.com
Tue Feb 19 15:05:28 PST 2008


"Janice Caron" wrote
> On 19/02/2008, Steven Schveighoffer wrote:
>> So please explain this:
>>
>> <snip>
>> // outputs 2 2 1 2
>
> Simple. If you wanted the output to be 2 2 2 2 then the second
> function should have
> been declared
>
>    void assignit(ref C src, ref C value)
>
> But you missed out the "ref"s, and so src was merely a local copy.
>
>
>> In both cases, the assignit function is taking reference types as 
>> arguments.
>
> But in the second case, the reference is /local/. Function parameters
> declared without "ref" are just local variables. Assigning src will
> modify the local copy (of the reference), but you need the "ref"
> keyword if you want to modify the original (reference).
>
>
>> Both do the same thing,
>
> No, they don't. Passing a value by reference is not the same thing as
> passing a reference by value.

You missed the point completely.  I'm not asking to find bugs in my code, 
I'm rebutting Walter's argument that "a reference is not separable from what 
it refers to".  If this was true in the current compiler, then I would 
expect the output to be 2 2 2 2, because assigning one reference to another 
should be like copying the value, right?

Walter's argument is like saying "If the sky wasn't green, then dragons 
wouldn't exist".  I'm not arguing his point about dragons, I'm saying, "wait 
a minute, the sky isn't green."

-Steve 





More information about the Digitalmars-d mailing list