Is there a way to statically-initialize a dynamically-allocated array in C++?

Viewed 14927

In C++, I can statically initialize an array, e.g.:

int a[] = { 1, 2, 3 };

Is there an easy way to initialize a dynamically-allocated array to a set of immediate values?

int *p = new int[3];
p = { 1, 2, 3 }; // syntax error

...or do I absolutely have to copy these values manually?

6 Answers
Related