Passing a reference to a returned reference
Michael
michael at toohuman.io
Fri Jul 6 16:56:44 UTC 2018
On Friday, 6 July 2018 at 16:24:03 UTC, Timoses wrote:
> On Friday, 6 July 2018 at 15:51:34 UTC, Michael wrote:
>> [...]
> While writing I realized that the following is even the case
> without the 'ref' parameter:
> The caller of the setter will still be able to change the
> content of your private data after you checked it for validity.
> Take following example:
>
> [...]
I understand your warning, but as the array is created purely to
assign to the agent's beliefs, it only appears in the main()
function as a rhs reference, which is passed to the agent, the
reference is stored in the member variable, and then the main
function continues, holding no reference to that array outside of
agent's agent.beliefs getter function. Appreciate the heads up,
though.
More information about the Digitalmars-d-learn
mailing list