still confused about call by reference

Bill Baxter dnewsgroup at billbaxter.com
Fri Nov 2 13:37:21 PDT 2007


Hoenir wrote:
>> In D that's written:
>>
>> void foo(ref Struct S)
>> {...}
>>
>> And called like:
>>
>> Struct s;
>> foo(s);
>>
>> --bb
> 
> Ok, but ref is an alias for inout atm. And I think "in" is implicitly 
> used if nothing other is specified, isn't it?

Yes.

> So how would I pass a struct by reference but without being able to 
> write (const & in C++)? and does this make sense(why is struct a value 
> type)?
> 
> Please excuse my noob questions. :-)

Sorry, I'm using D1.x.  What you ask is not possible with D1.x.
I expect as others have said that "const ref" will do it in D2.x as soon 
as that stops crashing the compiler.

--bb


More information about the Digitalmars-d-learn mailing list