Make sure lifetime of helper structs is less than owning struct
mail at skoppe.eu
Tue Nov 16 08:35:29 UTC 2021
On Monday, 15 November 2021 at 22:49:12 UTC, Ali Çehreli wrote:
> Trying with it produces an error when 'new' is not used:
> Error: reference to local variable `file` assigned to non-scope
> parameter `p` calling deneme.ByChunk.opAssign
The error is what the OP wanted, so that is expected.
Although, he did ask for it to be on the next line, but this is
better since it points exactly to the line where he was escaping
a reference to the scoped object.
> I don't see how it solves the problem. Sebastiaan Koppe might
> have intended to allocate the object dynamically with 'new' as
No I didn't. Anything created with new has automatic lifetime.
Here the OP wanted to (have the compiler) destroy the FileReader
when it left the scope, while disallowing any use after free.
More information about the Digitalmars-d-learn