How to properly pass structs to sub-functions?

AEon aeon2001 at lycos.de
Thu Sep 18 12:15:29 PDT 2008


BCS wrote:
> Reply to AEon,
> 
>> I used an - initially global -  struct with many entries to let me
>> save all sorts of data. The idea was to let me have to specify only
>> *one* parameter in all the subfunctions I use, and to let the
>> subfunctions change the data.
>>
>> Problem: It turns out data changed in the struct, in the
>> subfunction, is not remembered in the calling
>> function.
> 
> by default, structs are pass by value, use the "ref" attibut or switch 
> to a class
> 
> void theFn(ref MyStr str){...}

I had been thinking, "if this was C, I must not be passing the struct 
via pointer"... thank you so much for the very quick answer. Works like 
a charm now.

AEon


More information about the Digitalmars-d-learn mailing list