References

Graham Fawcett fawcett at uwindsor.ca
Mon Nov 28 10:06:39 PST 2011


On Mon, 28 Nov 2011 17:41:08 -0800, David Currie wrote:

> I am a newbie to D. From (C++,Java,others...) background.
> 
> In C++ I can say
> 
> void f1(int& pInt)
> {
>    pInt = 1;
> }
> 
> which sets pInt(which is outside f1)
> because although pInt (at compile time) is a Value in reality it is
> passed by reference(address).
> 
> Now
> 
> void f2(int* pIntPtr)
> {
>    *pIntPtr = 1;
>    ++pIntPtr;
>    *pInt   = 2;
> }
> sets (the contents of) pInt to 1 (and the next immediate address to 2)
> 
> All this is of course standard C++.
> 
> How is this type of thing done in D
> (changing objects by passing by reference etc)?

Try 

void f1(ref int pInt)

Graham



More information about the Digitalmars-d-learn mailing list