Initialization of array on heap
- by Radek Šimko
How do i manually initiate values in array on heap?
If the array is local variable (in stack), it can be done very elegant and easy way, like this:
int myArray[3] = {1,2,3};
Unfortunately, following code
int * myArray = new int[3];
myArray = {1,2,3};
outputs an error by compiling
error: expected primary-expression before ‘{’ token
error: expected `;' before ‘{’ token
Do i have to use cycle, or not-so-much-elegant way like this?
myArray[0] = 1;
myArray[1] = 2;
myArray[2] = 3;