Passing a reference to a returned reference
Michael
michael at toohuman.io
Fri Jul 6 13:13:43 UTC 2018
Hello,
I'm a little confused about what is actually happening when I try
to pass a reference, returned by a method that produces the
object (associative array), to a setter method which expects a
reference. What seems to be happening is that it simply does
nothing, as if the setter method is never called.
I'll try to provide some code to highlight the signatures.
The setter method being called on the reference returned by the
method that produces the array:
agent.beliefs = combination( ... ); // should receive a
reference, and pass this to the setter method.
Combination is a function point to one of two functions, whose
signatures look like:
static auto ref consensus( ... )
and the agent's setter method looks like the following:
void beliefs(ref double[int] beliefs)
Now obviously if I remove ref in the above signature, everything
works fine, but I am surprised I wasn't getting any kind of
warning about the reference because the setter function just
doesn't run at all. I tried checking if (beliefs is null) but
perhaps this isn't the correct way to check if an associative
array's reference is no longer reachable?
Some explanation would be great, thanks!
More information about the Digitalmars-d-learn
mailing list