<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 20, 2017 at 12:19 AM, SrMordred via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wednesday, 19 July 2017 at 14:09:32 UTC, SrMordred wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wednesday, 19 July 2017 at 09:09:40 UTC, Stefan Koch wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wednesday, 19 July 2017 at 07:48:28 UTC, Danni Coy wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Is there a reason that the following code<br>
<br>
struct Foo<br>
{<br>
    this (string name)<br>
    { do_something(name); }<br>
<br>
    ~this()<br>
    { undo_something(); }<br>
}<br>
<br>
Foo foo = void;<br>
<br>
void open()<br>
{<br>
    foo = Foo("test"); // <- this line<br>
}<br>
<br>
tries to OpAssign foo to itself then calls foo's destructor?<br>
</blockquote>
<br>
What happens is this.<br>
<br>
void open()<br>
{<br>
  foo = () {<br>
  Foo _tmp = Foo.__ctor("test");<br>
  return _tmp;<br>
  } ();<br>
}<br>
</blockquote>
<br>
Hm, isnt that wrong?<br>
If I destroy resources on the dtor, wouldn't it invalidate the resource on the copy?<br>
Also, C++ behaves differently<br>
</blockquote>
<br></div></div>
No Sorry, it behaves almost the same.<br>
just in D ctor and dtor are not called on declaration even if you drop " = void".<br></blockquote><div><br></div><div>Is there a way to delay the initialisation of a struct? </div></div><br></div></div>