Quick int pointer allocation question

monarch_dodra monarchdodra at gmail.com
Fri Sep 14 03:14:41 PDT 2012


On Friday, 14 September 2012 at 09:22:09 UTC, monarch_dodra wrote:
> On Friday, 14 September 2012 at 09:20:03 UTC, monarch_dodra 
> wrote:
>> This is going to be quick: Is it possible to allocate and 
>> initialize an int in the same line?
>>
>> int* p = new int(5);
>>
>> I haven't found a way to 1 liner it. Is it possible?
>> Do I have to two liner it?
>>
>> int* p = new int();
>> *p = 5;
>>
>> Thanks.
>
> Or dup a pointer to an int for that matter:
>
> int* p1 = ... ;
> int* p2 = p1.dup;
>
> ?

Whilst I'm on the subject of questions, how does one allocate, 
but bypassing the extra memcpy of T.init? Is this possible?


More information about the Digitalmars-d-learn mailing list