Object as function argument

w0rp via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 5 11:48:36 PST 2015


On Thursday, 5 March 2015 at 19:35:35 UTC, Chris Sperandio wrote:
> Hi,
>
> I'm a developer coming from C and I've a question about class 
> instance as method or function parameter.
> In the book "The D Programming Language", I read the instance 
> was passed by reference to functions (in the opposite of 
> structures). I understood that it was the same object in the 
> function and the caller. But I'm think, I was wrong because 
> when I print the addresses of an object before the function 
> call and inside the function, they're not the same but the 
> changes from the function are kept in the instance.
> If I use the "ref" qualifier in the function declaration, the 2 
> addresses are the same.
>
> How do the changes work in the function? Is there a copy ? Or a 
> "magic" trick :) ?
>
> Chris

If you share your code, I'll be happy to take a look. Classes are 
reference types, so passing T for a class should pass the 
reference to the object.


More information about the Digitalmars-d-learn mailing list