Quick int pointer allocation question
Jonathan M Davis
jmdavisProg at gmx.com
Fri Sep 14 03:37:45 PDT 2012
On Friday, September 14, 2012 11:20:16 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?
Nope. Though I think that it should be.
> Do I have to two liner it?
>
> int* p = new int();
> *p = 5;
Yep. Though I have a pull request which will make it so that you can do
auto p = makeNew!int(5);
https://github.com/D-Programming-Language/phobos/pull/756
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list