ref struct member function
Steven Schveighoffer
schveiguy at gmail.com
Thu May 13 19:40:58 UTC 2021
On 5/13/21 3:21 PM, PinDPlugga wrote:
> This works but issues a deprecation warning:
> ```
> onlineapp.d(30): Deprecation: returning `this` escapes a reference to
> parameter `this`
> onlineapp.d(30): perhaps annotate the parameter with `return`
> Fraction(1, 3)
> ```
>
> I found several other ways to make this work without the warnings, but I
> am wondering how to make this particular case work, or if it is not a
> recommended way, what the proper way would be.
Just follow the recommendation:
```d
ref Fraction reduce() return { // annotated with return
```
This means, "I will return all or part of the parameter passed in" (the
parameter being the `this` reference)
-Steve
More information about the Digitalmars-d-learn
mailing list