Will D 2.x have refrences

Bill Baxter dnewsgroup at billbaxter.com
Thu Oct 11 05:51:11 PDT 2007


Jari-Matti Mäkelä wrote:
> BLS wrote:
> 
>> I mean something comparable to :
>> //C++
>> int value = 100;
>> int & rIntRef = value;
>> if (rIntRef == 100)
>>    // be ashured my val is 100
>> rIntref = 101
>> if (&rIntref == &value)
>>    // Yes we have the same address
>>
>> (not parameter passing)
>> Bjoern
> 
> void main() {
>   int value = 100;
>   alias value rIntRef;
> 
>   if (rIntRef == 100)
>     rIntRef = 101;
> 
>   assert(value == 101);
>   assert(&value == &rIntRef);
> }
> 
> Alias parameters also work in functions wrapped inside templates.

But they don't work for things that require '.'s to get to.

void main() {
    int& value = myClass.some.value_member; // C++, ok
    ...
}

void main() {
    alias myClass.some.value_member  value;  // D, ack!
}

--bb



More information about the Digitalmars-d mailing list