[Issue 4247] Cannot create default-constructed struct on heap when constructor is defined

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 15 10:26:39 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=4247



--- Comment #9 from Steven Schveighoffer <schveiguy at yahoo.com> 2013-04-15 10:26:37 PDT ---
(In reply to comment #8)
> (In reply to comment #0)
> > So the auto s = new S is no longer usable.  However, I can easily declare a
> > struct S on the stack, or create a new array of S.  In fact, you can do:
> > 
> > auto s = (new S[1])[0];
> > 
> > and achieve the desired effect, but this is oh so ugly.
> 
> This code would create structure on the heap and put COPY of it to `s`.
> It is not the same as `auto s = new S`.
> 
> The workaround should be:
> --------------------
> auto s = (new S[1]).ptr;
> --------------------

Oh yes!  I was missing an & :)

Thanks

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list