January 15, 2016 Structs intended to run destructor immediately if not assigned to a variable? | ||||
---|---|---|---|---|
| ||||
Returning a struct with a destructor and not binding it to a variable appears to make the destructor run immediately instead of at the end of the scope. Is this intended? example: http://dpaste.dzfl.pl/dd285200ba2b |
January 14, 2016 Re: Structs intended to run destructor immediately if not assigned to a variable? | ||||
---|---|---|---|---|
| ||||
Posted in reply to rsw0x | On 01/14/2016 09:23 PM, rsw0x wrote: > Returning a struct with a destructor and not binding it to a variable > appears to make the destructor run immediately instead of at the end of > the scope. > Is this intended? > > example: > http://dpaste.dzfl.pl/dd285200ba2b Assuming that this rule is the same as in C++ (and I think so), the lifetime of a temporary variable is the whole expression that created it. So, the behaviour you are describing is intended. Ali |
Copyright © 1999-2021 by the D Language Foundation