Copy a struct on the heap and get the pointer to it.

Martin Nowak dawg at dawgfoto.de
Sat Nov 12 08:52:32 PST 2011


On Sat, 12 Nov 2011 17:41:56 +0100, Martin Nowak <dawg at dawgfoto.de> wrote:

> On Sat, 12 Nov 2011 17:41:43 +0100, deadalnix <deadalnix at gmail.com>  
> wrote:
>
>> Le 12/11/2011 16:29, Andrei Alexandrescu a écrit :
>>> On 11/12/11 8:39 AM, deadalnix wrote:
>>>> Hi all,
>>>>
>>>> We recently had a discution on #D about copying a struct on the heap  
>>>> and
>>>> getting a pointer to it.
>>>>
>>>> We come up with the following solution (Thanks to CyberShadow !) :
>>>>
>>>> struct S;
>>>> S s; // Allocated locally.
>>>> [s].ptr; // Get a pointer to a copy in the heap of the struct
>>>
>>> This should work:
>>>
>>> S s;
>>> auto p = new S(s);
>>>
>>> It's a bug in the compiler if it doesn't. Unfortunately it doesn't for
>>> primitive types, e.g. new int(5) does not work.
>>>
>>>
>>> Andrei
>>
>> That was my first try. It does not work.
>
> I'll make bug reports for it.

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

It's actually two bugs.
If the 6937 worked one could have used 'new S(s.tupleof)'.

martin


More information about the Digitalmars-d mailing list