Copy a struct on the heap and get the pointer to it.
kenji hara
k.hara.pg at gmail.com
Sat Nov 12 07:54:48 PST 2011
It has been already filed in bugzilla?
If so, I'd like to fix it.
Kenji Hara
2011/11/13 Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:
> 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
>
More information about the Digitalmars-d
mailing list